From 2e341ef65930ddf3d28f9d88f27ff7adfa547f44 Mon Sep 17 00:00:00 2001 From: stfwi Date: Wed, 1 Sep 2021 20:28:23 +0200 Subject: [PATCH] Fixed Factory Hopper UI element events. --- gradle.properties | 2 +- meta/update.json | 3 +- readme.md | 2 + .../blocks/EdCraftingTable.java | 4 +- .../wile/engineersdecor/blocks/EdDropper.java | 4 +- .../blocks/EdElectricalFurnace.java | 6 +-- .../wile/engineersdecor/blocks/EdFurnace.java | 5 ++- .../wile/engineersdecor/blocks/EdHopper.java | 3 +- .../blocks/EdMineralSmelter.java | 42 +++++++++++-------- .../wile/engineersdecor/blocks/EdPlacer.java | 3 +- 10 files changed, 44 insertions(+), 30 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4b0ecc6..71ab5c0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ org.gradle.jvmargs=-Xmx8G version_minecraft=1.17.1 version_forge_minecraft=1.17.1-37.0.51 version_jei=1.17.1:8.0.0.15 -version_engineersdecor=1.1.17-b2 +version_engineersdecor=1.1.17-b3 diff --git a/meta/update.json b/meta/update.json index 9c4de0b..0314e1d 100644 --- a/meta/update.json +++ b/meta/update.json @@ -1,6 +1,7 @@ { "homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/", "1.17.1": { + "1.1.17-b3": "[F] Fixed Factory Hopper GUI element events.", "1.1.17-b2": "[F] Updated to Forge 1.17.1-37.0.51 to fix `ToolType not found` startup crash.\n[A] JEI plugin enabled.\n[A] Dark Shingle Roof recipe variant added.", "1.1.17-b1": "[U] Initial MC 1.17.1 port.\n[M] Clinker Brick textures adapted to contemporary MC textures.\n[D] Gas Concrete dropped (Rebar Concrete suffices for texture variation).\n[D] Treated Wood Side Table dropped.\n[M] Updated zh_cn (PR#183, Lyaiya).", "1.1.14": "[R] Release build v1.1.14.", @@ -42,6 +43,6 @@ }, "promos": { "1.17.1-recommended": "1.1.14", - "1.17.1-latest": "1.1.17-b2" + "1.17.1-latest": "1.1.17-b3" } } \ No newline at end of file diff --git a/readme.md b/readme.md index d58f8d1..464f819 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,8 @@ Mod sources for Minecraft version 1.16.x. ## Version history + - v1.1.17-b3 [F] Fixed Factory Hopper GUI element events. + - v1.1.17-b2 [F] Updated to Forge 1.17.1-37.0.51 to fix `ToolType not found` startup crash. [A] JEI plugin enabled. [A] Dark Shingle Roof recipe variant added. diff --git a/src/main/java/wile/engineersdecor/blocks/EdCraftingTable.java b/src/main/java/wile/engineersdecor/blocks/EdCraftingTable.java index 31d025b..c6182d5 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdCraftingTable.java +++ b/src/main/java/wile/engineersdecor/blocks/EdCraftingTable.java @@ -331,8 +331,8 @@ public class EdCraftingTable inventory_ = block_inventory; inventory_.startOpen(player_); Level world = player_.level; - if((inventory_ instanceof StorageInventory) && ((((StorageInventory)inventory_).getTileEntity()) instanceof CraftingTableTileEntity)) { - te_ = (CraftingTableTileEntity)(((StorageInventory)inventory_).getTileEntity()); + if((inventory_ instanceof StorageInventory) && ((((StorageInventory)inventory_).getTileEntity()) instanceof final CraftingTableTileEntity te)) { + te_ = te; } else { te_ = null; } diff --git a/src/main/java/wile/engineersdecor/blocks/EdDropper.java b/src/main/java/wile/engineersdecor/blocks/EdDropper.java index 40cf28b..b17110e 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdDropper.java +++ b/src/main/java/wile/engineersdecor/blocks/EdDropper.java @@ -735,7 +735,8 @@ public class EdDropper @Override public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt) { - if((!(inventory_ instanceof StorageInventory)) || (!(((StorageInventory)inventory_).getTileEntity() instanceof DropperTileEntity))) return; + if(!(inventory_ instanceof Inventories.StorageInventory)) return; + if(!(((Inventories.StorageInventory)inventory_).getTileEntity() instanceof final DropperTileEntity te)) return; if(nbt.contains("action")) { boolean changed = false; final int slotId = nbt.contains("slot") ? nbt.getInt("slot") : -1; @@ -754,7 +755,6 @@ public class EdDropper broadcastChanges(); } } else { - DropperTileEntity te = (DropperTileEntity)((StorageInventory)inventory_).getTileEntity(); if(nbt.contains("drop_speed")) te.drop_speed_ = Mth.clamp(nbt.getInt("drop_speed"), 0, 100); if(nbt.contains("drop_xdev")) te.drop_xdev_ = Mth.clamp(nbt.getInt("drop_xdev"), -100, 100); if(nbt.contains("drop_ydev")) te.drop_ydev_ = Mth.clamp(nbt.getInt("drop_ydev"), -100, 100); diff --git a/src/main/java/wile/engineersdecor/blocks/EdElectricalFurnace.java b/src/main/java/wile/engineersdecor/blocks/EdElectricalFurnace.java index ec710e1..da5625f 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdElectricalFurnace.java +++ b/src/main/java/wile/engineersdecor/blocks/EdElectricalFurnace.java @@ -716,8 +716,8 @@ public class EdElectricalFurnace protected void checkTakeAchievements(ItemStack stack) { stack.onCraftedBy(player_.level, player_, removeCount); - if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory)) { - ElectricalFurnaceTileEntity te = (ElectricalFurnaceTileEntity)(((StorageInventory)inventory_).getTileEntity()); + if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory) && + (((StorageInventory)inventory_).getTileEntity()) instanceof final ElectricalFurnaceTileEntity te) { int xp = te.consumeSmeltingExperience(stack); while(xp > 0) { int k = ExperienceOrb.getExperienceValue(xp); @@ -838,7 +838,7 @@ public class EdElectricalFurnace public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt) { if(!(inventory_ instanceof StorageInventory)) return; - ElectricalFurnaceTileEntity te = (ElectricalFurnaceTileEntity)(((StorageInventory)inventory_).getTileEntity()); + if(!((((StorageInventory)inventory_).getTileEntity()) instanceof final ElectricalFurnaceTileEntity te)) return; if(nbt.contains("speed")) te.speed_ = Mth.clamp(nbt.getInt("speed"), 0, ElectricalFurnaceTileEntity.MAX_SPEED_SETTING); te.setChanged(); } diff --git a/src/main/java/wile/engineersdecor/blocks/EdFurnace.java b/src/main/java/wile/engineersdecor/blocks/EdFurnace.java index 8d1600a..796028f 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdFurnace.java +++ b/src/main/java/wile/engineersdecor/blocks/EdFurnace.java @@ -706,8 +706,9 @@ public class EdFurnace protected void checkTakeAchievements(ItemStack stack) { stack.onCraftedBy(player_.level, player_, removeCount); - if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory)) { - FurnaceTileEntity te = (FurnaceTileEntity)(((StorageInventory)inventory_).getTileEntity()); + if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory) && + ((((StorageInventory)inventory_).getTileEntity()) instanceof final FurnaceTileEntity te) + ) { int xp = te.consumeSmeltingExperience(stack); while(xp > 0) { int k = ExperienceOrb.getExperienceValue(xp); diff --git a/src/main/java/wile/engineersdecor/blocks/EdHopper.java b/src/main/java/wile/engineersdecor/blocks/EdHopper.java index 1165c50..94b94d8 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdHopper.java +++ b/src/main/java/wile/engineersdecor/blocks/EdHopper.java @@ -716,7 +716,8 @@ public class EdHopper @Override public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt) { - if(!(inventory_ instanceof HopperTileEntity te)) return; + if(!(inventory_ instanceof Inventories.StorageInventory)) return; + if(!((((((Inventories.StorageInventory)inventory_).getTileEntity())) instanceof final EdHopper.HopperTileEntity te))) return; if(nbt.contains("xsize")) te.transfer_count_ = Mth.clamp(nbt.getInt("xsize"), 1, HopperTileEntity.MAX_TRANSFER_COUNT); if(nbt.contains("period")) te.transfer_period_ = Mth.clamp(nbt.getInt("period"), 0, 100); if(nbt.contains("range")) te.collection_range_ = Mth.clamp(nbt.getInt("range"), 0, HopperTileEntity.MAX_COLLECTION_RANGE); diff --git a/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java b/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java index e7180f9..0cbbb46 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java +++ b/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java @@ -223,7 +223,7 @@ public class EdMineralSmelter public static final int MAX_ENERGY_BUFFER = 32000; public static final int MAX_ENERGY_TRANSFER = 8192; public static final int DEFAULT_ENERGY_CONSUMPTION = 92; - public static final int DEFAULT_HEATUP_RATE = 2; // -> 50s for one smelting process + public static final int DEFAULT_HEATUP_RATE = 10; //2; // -> 50s for one smelting process public static final int PHASE_WARMUP = 0; public static final int PHASE_HOT = 1; public static final int PHASE_MAGMABLOCK = 2; @@ -267,7 +267,7 @@ public class EdMineralSmelter .setStackLimit(1) .setValidator((index,stack)-> ((index==1) || ((index==0) && accepts_input(stack)))) .setSlotChangeAction((slot,stack)->{ - System.out.println("slot"+slot+"<<"+stack); + //System.out.println("slot"+slot+"<<"+stack); }); item_handler_ = Inventories.MappedItemHandler.createGenericHandler( main_inventory_, @@ -329,10 +329,15 @@ public class EdMineralSmelter return stack; } + protected void drain_lava_bucket() + { + } + protected void reset_process() { main_inventory_.setItem(0, ItemStack.EMPTY); main_inventory_.setItem(1, ItemStack.EMPTY); + tank_.clear(); force_block_update_ = true; tick_timer_ = 0; progress_ = 0; @@ -396,14 +401,14 @@ public class EdMineralSmelter boolean dirty = false; final int last_phase = phase(); final ItemStack istack = main_inventory_.getItem(0); - if(istack.isEmpty() && tank_.isEmpty()) { + if(istack.isEmpty() && (tank_.getFluidAmount()<1000)) { progress_ = 0; } else if((battery_.isEmpty()) || (level.hasNeighborSignal(worldPosition))) { progress_ = Mth.clamp(progress_-cooldown_rate, 0,100); } else if(progress_ >= 100) { progress_ = 100; if(!battery_.draw(energy_consumption*TICK_INTERVAL/20)) battery_.clear(); - } else { + } else if((phase()>=PHASE_LAVA) || (!istack.isEmpty())) { if(!battery_.draw(energy_consumption*TICK_INTERVAL)) battery_.clear(); progress_ = Mth.clamp(progress_+heatup_rate, 0, 100); } @@ -447,9 +452,13 @@ public class EdMineralSmelter // Cool-down to prev phase happened. switch(new_phase) { case PHASE_MAGMABLOCK -> { - main_inventory_.setItem(0, (tank_.getFluidAmount() >= MAX_BUCKET_EXTRACT_FLUID_LEVEL) ? (MAGMA_STACK.copy()) : (ItemStack.EMPTY)); - main_inventory_.setItem(1, main_inventory_.getItem(0).copy()); - tank_.clear(); + if(tank_.getFluidAmount() < 1000) { + reset_process(); + } else { + main_inventory_.setItem(0, (tank_.getFluidAmount() >= MAX_BUCKET_EXTRACT_FLUID_LEVEL) ? (MAGMA_STACK.copy()) : (ItemStack.EMPTY)); + main_inventory_.setItem(1, main_inventory_.getItem(0).copy()); + tank_.clear(); + } level.playSound(null, worldPosition, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 1.1f); dirty = true; } @@ -466,17 +475,16 @@ public class EdMineralSmelter level.playSound(null, worldPosition, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.3f, 0.7f); } } - } else if((phase()==PHASE_LAVA) && fluid_extraction_possible()) { + } else if((phase()==PHASE_LAVA) && (tank_.getFluidAmount()>0)) { // Phase unchanged, fluid transfer check. - final IFluidHandler fh = Fluidics.handler(level, getBlockPos().below(), Direction.UP); - if(fh != null) { - int n = fh.fill(LAVA_BUCKET_FLUID_STACK.copy(), IFluidHandler.FluidAction.SIMULATE); - if(n >= LAVA_BUCKET_FLUID_STACK.getAmount()/2) { - n = fh.fill(LAVA_BUCKET_FLUID_STACK.copy(), IFluidHandler.FluidAction.EXECUTE); - if(n > 0) { - reset_process(); - level.playSound(null, worldPosition, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.3f, 0.7f); - } + FluidStack fs = tank_.getFluid().copy(); + if(fs.getAmount() > 100) fs.setAmount(100); + final int n = Fluidics.fill(level, getBlockPos().below(), Direction.UP, fs); + if(n > 0) { + tank_.drain(n); + if(tank_.isEmpty()) { + reset_process(); + level.playSound(null, worldPosition, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.3f, 0.7f); } } } diff --git a/src/main/java/wile/engineersdecor/blocks/EdPlacer.java b/src/main/java/wile/engineersdecor/blocks/EdPlacer.java index 2d09647..da7dc0b 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdPlacer.java +++ b/src/main/java/wile/engineersdecor/blocks/EdPlacer.java @@ -652,7 +652,8 @@ public class EdPlacer @Override public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt) { - if((!(inventory_ instanceof Inventories.StorageInventory)) || (!((((Inventories.StorageInventory)inventory_).getTileEntity()) instanceof PlacerTileEntity te))) return; + if(!(inventory_ instanceof Inventories.StorageInventory)) return; + if(!((((Inventories.StorageInventory)inventory_).getTileEntity()) instanceof PlacerTileEntity te)) return; if(nbt.contains("action")) { final int slotId = nbt.contains("slot") ? nbt.getInt("slot") : -1; boolean changed = false;