Search code examples
javaminecraftminecraft-forge

Thaumcraft4 - Golem Core "Harvest" - Bug with magic beans


I've got a mana bean farm with different segments according of bean type each. There are golems with "Harvest" core and Ordo upgrade are harvesting them. They cannot reach the segments they are not bellongs. But sometimes I saw that in a neighbour segment is growing bean(s) with wrong aspect. In my case there are Vitium and Spiritus, but that is not important. Later I had an investigation of code and found something in it.

`

 void harvest() {
        this.count = 200;
        final int md = this.blockMd;
        final FakePlayer fp = FakePlayerFactory.get((WorldServer)this.theWorld, new GameProfile((UUID)null, "FakeThaumcraftGolem"));
        fp.func_70107_b(this.theGolem.field_70165_t, this.theGolem.field_70163_u, this.theGolem.field_70161_v);
        if (CropUtils.clickableCrops.contains(this.block.func_149739_a() + md)) {
            this.block.func_149727_a(this.theWorld, this.xx, this.yy, this.zz, (EntityPlayer)fp, 0, 0.0f, 0.0f, 0.0f);
        }
        else {
            this.theWorld.func_147480_a(this.xx, this.yy, this.zz, true);
            if (this.theGolem.getUpgradeAmount(4) > 0) {
                final ArrayList<ItemStack> items = new ArrayList<ItemStack>();
                final ArrayList<Entity> drops = (ArrayList<Entity>)EntityUtils.getEntitiesInRange(this.theWorld, this.theGolem.field_70165_t, this.theGolem.field_70163_u, this.theGolem.field_70161_v, (Entity)this.theGolem, (Class)EntityItem.class, 6.0);
                if (drops.size() > 0) {
                    for (final Entity e : drops) {
                        if (e instanceof EntityItem) {
                            if (e.field_70173_aa < 2) {
                                Vec3 v = Vec3.func_72443_a(e.field_70165_t - this.theGolem.field_70165_t, e.field_70163_u - this.theGolem.field_70163_u, e.field_70161_v - this.theGolem.field_70161_v);
                                v = v.func_72432_b();
                                e.field_70159_w = -v.field_72450_a / 4.0;
                                e.field_70181_x = 0.075;
                                e.field_70179_y = -v.field_72449_c / 4.0;
                            }
                            boolean done = false;
                            final EntityItem item = (EntityItem)e;
                            final ItemStack st = item.func_92059_d();
                            if (st.func_77973_b() != null && st.func_77973_b() == Items.field_151100_aR && st.func_77960_j() == 3) {
                                final int var5 = BlockDirectional.func_149895_l(this.blockMd);
                                final int par2 = this.xx + Direction.field_71583_a[var5];
                                final int par3 = this.zz + Direction.field_71581_b[var5];
                                final Block var6 = this.theWorld.func_147439_a(par2, this.yy, par3);
                                if (var6 == Blocks.field_150364_r && BlockLog.func_150165_c(this.theWorld.func_72805_g(par2, this.yy, par3)) == 3) {
                                    final ItemStack itemStack = st;
                                    --itemStack.field_77994_a;
                                    this.theWorld.func_147465_d(this.xx, this.yy, this.zz, Blocks.field_150375_by, BlockDirectional.func_149895_l(this.blockMd), 3);
                                }
                                done = true;
                            }
                            else if (st.func_77973_b() != null && st.func_77973_b() == ConfigItems.itemManaBean) {
                                if (this.block.func_149707_d(this.theWorld, this.xx, this.yy, this.zz, 0)) {
                                    final ItemStack itemStack2 = st;
                                    --itemStack2.field_77994_a;
                                    if (!st.func_77973_b().func_77648_a(st.func_77946_l(), (EntityPlayer)fp, this.theWorld, this.xx, this.yy + 1, this.zz, 0, 0.5f, 0.5f, 0.5f)) {
                                        this.theWorld.func_147465_d(this.xx, this.yy, this.zz, ConfigBlocks.blockManaPod, 0, 3);
                                    }
                                }
                                done = true;
                            }
                            else {
                                final int[] xm = { 0, 0, 1, 1, -1, 0, -1, -1, 1 };
                                final int[] zm = { 0, 1, 0, 1, 0, -1, -1, 1, -1 };
                                for (int count = 0; st != null && st.field_77994_a > 0 && count < 9; ++count) {
                                    if (st.func_77973_b() != null && (st.func_77973_b() instanceof IPlantable || st.func_77973_b() instanceof ItemSeedFood) && st.func_77973_b().func_77648_a(st.func_77946_l(), (EntityPlayer)fp, this.theWorld, this.xx + xm[count], this.yy - 1, this.zz + zm[count], ForgeDirection.UP.ordinal(), 0.5f, 0.5f, 0.5f)) {
                                        final ItemStack itemStack3 = st;
                                        --itemStack3.field_77994_a;
                                    }
                                }
                            }
                            if (st.field_77994_a <= 0) {
                                item.func_70106_y();
                            }
                            else {
                                item.func_92058_a(st);
                            }
                            if (done) {
                                break;
                            }
                            continue;
                        }
                    }
                }
            }
        }
        fp.func_70106_y();
        this.theGolem.startActionTimer();
    }

`

The key is in first 'else' is starts with condition "this.theGolem.getUpgradeAmount(4) > 0". I've seen in the different file that upgrade with 4 ID is exactly an Ordo upgrade, but I'm not familiar with Java and I can't see what's going on here and how to fix my problem with "beans shuffle". Is anybody have any clue how to override this logic or where actually in code is caused a problem? Preventively thanks for any answer


Solution

  • Well, I didn't get an answer after searching this code, but I accidently found that golem is trying to replace bean with dropped ones. That technicaly solved my problem by half. this.theWorld.func_147465_d(this.xx, this.yy, this.zz, ConfigBlocks.blockManaPod, 0, 3); This line is telling me about this, but it has no clue about specific aspect, random only