From 5a60aa48650783c6c2fd1d7542ac031fc0045a40 Mon Sep 17 00:00:00 2001 From: stfwi Date: Thu, 9 Sep 2021 21:12:32 +0200 Subject: [PATCH] Mineral Melter refurbished. Fixed Small Block Placer item insertion. --- gradle.properties | 2 +- meta/update.json | 3 +- readme.md | 3 + .../java/wile/engineersdecor/ModConfig.java | 4 +- .../wile/engineersdecor/blocks/EdDropper.java | 3 - .../wile/engineersdecor/blocks/EdHopper.java | 3 - .../blocks/EdMineralSmelter.java | 32 +++---- .../wile/engineersdecor/blocks/EdPlacer.java | 47 ++++------ .../blocks/EdWasteIncinerator.java | 87 +------------------ .../libmc/detail/Inventories.java | 28 ++++-- 10 files changed, 61 insertions(+), 151 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6884bd6..c527bca 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-b4 +version_engineersdecor=1.1.17-b5 diff --git a/meta/update.json b/meta/update.json index 2bac1c0..b0120b7 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-b5": "[F] Refurbished Mineral Melter code.\n[F] Fixed Block Placer item insertion.", "1.1.17-b4": "[F] Config event update fixed.\n[F] Milker fluid tank handling issue fixed.\n[F] Device collision shapes adapted to allow attaching levers.", "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.", @@ -44,6 +45,6 @@ }, "promos": { "1.17.1-recommended": "1.1.14", - "1.17.1-latest": "1.1.17-b4" + "1.17.1-latest": "1.1.17-b5" } } \ No newline at end of file diff --git a/readme.md b/readme.md index 2f30f03..90485a0 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,9 @@ Mod sources for Minecraft version 1.16.x. ## Version history + - v1.1.17-b5 [F] Refurbished Mineral Melter code. + [F] Fixed Block Placer item insertion. + - v1.1.17-b4 [F] Config event update fixed. [F] Milker fluid tank handling issue fixed. [F] Device collision shapes adapted to allow attaching levers. diff --git a/src/main/java/wile/engineersdecor/ModConfig.java b/src/main/java/wile/engineersdecor/ModConfig.java index 2827384..fa12253 100644 --- a/src/main/java/wile/engineersdecor/ModConfig.java +++ b/src/main/java/wile/engineersdecor/ModConfig.java @@ -456,8 +456,8 @@ public class ModConfig EdElectricalFurnace.on_config(SERVER.e_furnace_speed_percent.get(), SERVER.e_furnace_power_consumption.get(), SERVER.e_furnace_automatic_pulling.get()); EdSolarPanel.on_config(SERVER.small_solar_panel_peak_production.get(), 64000, 1024); EdMilker.on_config(SERVER.milking_machine_energy_consumption.get(), SERVER.milking_machine_milking_delay.get()); - EdFreezer.on_config(92, 2); - EdMineralSmelter.on_config(92, 2); + EdFreezer.on_config(144, 2); + EdMineralSmelter.on_config(144, 2); EdWasteIncinerator.on_config(8); // ----------------------------------------------------------------------------------------------------------------- { diff --git a/src/main/java/wile/engineersdecor/blocks/EdDropper.java b/src/main/java/wile/engineersdecor/blocks/EdDropper.java index b17110e..5abd80a 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdDropper.java +++ b/src/main/java/wile/engineersdecor/blocks/EdDropper.java @@ -286,9 +286,6 @@ public class EdDropper tick_timer_ = 1; } - public boolean is_input_slot(int index) - { return (index >= INPUT_SLOTS_FIRST) && (index < (INPUT_SLOTS_FIRST+INPUT_SLOTS_SIZE)); } - // BlockEntity ------------------------------------------------------------------------------ @Override diff --git a/src/main/java/wile/engineersdecor/blocks/EdHopper.java b/src/main/java/wile/engineersdecor/blocks/EdHopper.java index 94b94d8..ac294eb 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdHopper.java +++ b/src/main/java/wile/engineersdecor/blocks/EdHopper.java @@ -266,9 +266,6 @@ public class EdHopper tick_timer_ = 1; } - public boolean is_input_slot(int index) - { return (index >= 0) && (index < NUM_OF_STORAGE_SLOTS); } - // BlockEntity -------------------------------------------------------------------------------------------- @Override diff --git a/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java b/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java index 441df11..4346d55 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java +++ b/src/main/java/wile/engineersdecor/blocks/EdMineralSmelter.java @@ -231,7 +231,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 = 10; //2; // -> 50s for one smelting process + public static final int DEFAULT_HEATUP_RATE = 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; @@ -271,16 +271,13 @@ public class EdMineralSmelter public MineralSmelterTileEntity(BlockPos pos, BlockState state) { super(ModContent.TET_MINERAL_SMELTER, pos, state); - main_inventory_ = (new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1)) - .setStackLimit(1) - .setValidator((index,stack)-> ((index==1) || ((index==0) && accepts_input(stack)))) - .setSlotChangeAction((slot,stack)->{ - //System.out.println("slot"+slot+"<<"+stack); - }); + main_inventory_ = (new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1)).setStackLimit(1); item_handler_ = Inventories.MappedItemHandler.createGenericHandler( main_inventory_, (index,stack)->((index==1) && (phase()!=PHASE_LAVA)), - (index,stack)->((index==0) && accepts_input(stack)) + (index,stack)->((index==0) && accepts_input(stack)), + (index,stack)->{}, + (index,stack)->{ if(index!=0) reset_process(); } ); } @@ -337,10 +334,6 @@ public class EdMineralSmelter return stack; } - protected void drain_lava_bucket() - { - } - protected void reset_process() { main_inventory_.setItem(0, ItemStack.EMPTY); @@ -409,8 +402,10 @@ public class EdMineralSmelter boolean dirty = false; final int last_phase = phase(); final ItemStack istack = main_inventory_.getItem(0); - if(istack.isEmpty() && (tank_.getFluidAmount()<1000)) { + if(istack.isEmpty() && (tank_.getFluidAmount()= 100) { @@ -420,12 +415,13 @@ public class EdMineralSmelter if(!battery_.draw(energy_consumption*TICK_INTERVAL)) battery_.clear(); progress_ = Mth.clamp(progress_+heatup_rate, 0, 100); } - int new_phase = phase(); + final int new_phase = phase(); if(accepts_lava_container(istack)) { // That stays in the slot until its extracted or somone takes it out. if(istack.sameItem(BUCKET_STACK)) { if(!main_inventory_.getItem(1).sameItem(LAVA_BUCKET_STACK)) { if(fluid_extraction_possible()) { + reset_process(); main_inventory_.setItem(1, LAVA_BUCKET_STACK); level.playSound(null, worldPosition, SoundEvents.BUCKET_FILL_LAVA, SoundSource.BLOCKS, 0.2f, 1.3f); } else { @@ -439,7 +435,7 @@ public class EdMineralSmelter } } else if(new_phase > last_phase) { // Heat-up to next phase happened. - switch (new_phase) { + switch(new_phase) { case PHASE_LAVA -> { tank_.fill(new FluidStack(Fluids.LAVA, 1000), IFluidHandler.FluidAction.EXECUTE); main_inventory_.setItem(1, ItemStack.EMPTY); @@ -460,11 +456,11 @@ public class EdMineralSmelter // Cool-down to prev phase happened. switch(new_phase) { case PHASE_MAGMABLOCK -> { - if(tank_.getFluidAmount() < 1000) { + if(tank_.getFluidAmount() < MAX_BUCKET_EXTRACT_FLUID_LEVEL) { 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()); + main_inventory_.setItem(0, MAGMA_STACK.copy()); + main_inventory_.setItem(1, MAGMA_STACK.copy()); tank_.clear(); } level.playSound(null, worldPosition, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 1.1f); diff --git a/src/main/java/wile/engineersdecor/blocks/EdPlacer.java b/src/main/java/wile/engineersdecor/blocks/EdPlacer.java index da7dc0b..e0035f9 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdPlacer.java +++ b/src/main/java/wile/engineersdecor/blocks/EdPlacer.java @@ -54,6 +54,7 @@ import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.IFluidBlock; +import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import wile.engineersdecor.ModContent; import wile.engineersdecor.ModEngineersDecor; @@ -197,10 +198,16 @@ public class EdPlacer private int current_slot_index_ = 0; private int tick_timer_ = 0; private final Inventories.StorageInventory inventory_ = new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1); - private final LazyOptional item_handler_ = Inventories.MappedItemHandler.createGenericHandler(inventory_); + private final LazyOptional item_handler_; public PlacerTileEntity(BlockPos pos, BlockState state) - { super(ModContent.TET_FACTORY_PLACER, pos, state); } + { + super(ModContent.TET_FACTORY_PLACER, pos, state); + item_handler_ = Inventories.MappedItemHandler.createGenericHandler(inventory_, + (stack, slot) -> true, + (stack, slot) -> true + ); + } public CompoundTag clear_getnbt() { @@ -246,9 +253,6 @@ public class EdPlacer } } - public boolean is_input_slot(int index) - { return (index >= 0) && (index < NUM_OF_SLOTS); } - // BlockEntity ------------------------------------------------------------------------------ @Override @@ -319,35 +323,14 @@ public class EdPlacer } }; - // ISidedInventory -------------------------------------------------------------------------------------- -// -// LazyOptional[] item_handlers = SidedInvWrapper.create(this, Direction.UP); -// private static final int[] SIDED_INV_SLOTS; -// static { -// SIDED_INV_SLOTS = new int[NUM_OF_SLOTS]; -// for(int i=0; i LazyOptional getCapability(net.minecraftforge.common.capabilities.Capability capability, @Nullable Direction facing) -// { -// if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return item_handlers[0].cast(); -// return super.getCapability(capability, facing); -// } + @Override + public LazyOptional getCapability(net.minecraftforge.common.capabilities.Capability capability, @Nullable Direction facing) + { + if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return item_handler_.cast(); + return super.getCapability(capability, facing); + } // ITickable and aux methods ---------------------------------------------------------------------------- diff --git a/src/main/java/wile/engineersdecor/blocks/EdWasteIncinerator.java b/src/main/java/wile/engineersdecor/blocks/EdWasteIncinerator.java index f0e862b..a7a42df 100644 --- a/src/main/java/wile/engineersdecor/blocks/EdWasteIncinerator.java +++ b/src/main/java/wile/engineersdecor/blocks/EdWasteIncinerator.java @@ -231,7 +231,7 @@ public class EdWasteIncinerator { super.setRemoved(); energy_handler_.invalidate(); -// item_handler_.invalidate(); + item_handler_.invalidate(); } // INameable --------------------------------------------------------------------------- @@ -282,91 +282,6 @@ public class EdWasteIncinerator } }; - - // IItemHandler -------------------------------------------------------------------------------- -// -// protected static class BItemHandler implements IItemHandler -// { -// private final WasteIncineratorTileEntity te; -// -// BItemHandler(WasteIncineratorTileEntity te) -// { this.te = te; } -// -// @Override -// public int getSlots() -// { return 1; } -// -// @Override -// public int getSlotLimit(int index) -// { return te.getMaxStackSize(); } -// -// @Override -// public boolean isItemValid(int slot, @Nonnull ItemStack stack) -// { return true; } -// -// @Override -// @Nonnull -// public ItemStack insertItem(int index, @Nonnull ItemStack stack, boolean simulate) -// { -// if(stack.isEmpty()) return ItemStack.EMPTY; -// if(index != 0) return ItemStack.EMPTY; -// int slotno = 0; -// ItemStack slotstack = getStackInSlot(slotno); -// if(!slotstack.isEmpty()) -// { -// if(slotstack.getCount() >= Math.min(slotstack.getMaxStackSize(), getSlotLimit(index))) return stack; -// if(!ItemHandlerHelper.canItemStacksStack(stack, slotstack)) return stack; -// if(!te.canPlaceItemThroughFace(slotno, stack, Direction.UP) || (!te.canPlaceItem(slotno, stack))) return stack; -// int n = Math.min(stack.getMaxStackSize(), getSlotLimit(index)) - slotstack.getCount(); -// if(stack.getCount() <= n) { -// if(!simulate) { -// ItemStack copy = stack.copy(); -// copy.grow(slotstack.getCount()); -// te.setItem(slotno, copy); -// } -// return ItemStack.EMPTY; -// } else { -// stack = stack.copy(); -// if(!simulate) { -// ItemStack copy = stack.split(n); -// copy.grow(slotstack.getCount()); -// te.setItem(slotno, copy); -// return stack; -// } else { -// stack.shrink(n); -// return stack; -// } -// } -// } else { -// if(!te.canPlaceItemThroughFace(slotno, stack, Direction.UP) || (!te.canPlaceItem(slotno, stack))) return stack; -// int n = Math.min(stack.getMaxStackSize(), getSlotLimit(index)); -// if(n < stack.getCount()) { -// stack = stack.copy(); -// if(!simulate) { -// te.setItem(slotno, stack.split(n)); -// return stack; -// } else { -// stack.shrink(n); -// return stack; -// } -// } else { -// if(!simulate) te.setItem(slotno, stack); -// return ItemStack.EMPTY; -// } -// } -// } -// -// @Override -// @Nonnull -// public ItemStack extractItem(int index, int amount, boolean simulate) -// { return ItemStack.EMPTY; } -// -// @Override -// @Nonnull -// public ItemStack getStackInSlot(int index) -// { return te.getItem(index); } -// } - // Capability export ---------------------------------------------------------------------------- @Override diff --git a/src/main/java/wile/engineersdecor/libmc/detail/Inventories.java b/src/main/java/wile/engineersdecor/libmc/detail/Inventories.java index d3abd85..53091d6 100644 --- a/src/main/java/wile/engineersdecor/libmc/detail/Inventories.java +++ b/src/main/java/wile/engineersdecor/libmc/detail/Inventories.java @@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.*; import net.minecraft.world.entity.Entity; @@ -157,11 +156,19 @@ public class Inventories { private final BiPredicate extraction_predicate_; private final BiPredicate insertion_predicate_; + private final BiConsumer insertion_notifier_; + private final BiConsumer extraction_notifier_; private final List slot_map_; private final Container inv_; + public MappedItemHandler(Container inv, BiPredicate extraction_predicate, BiPredicate insertion_predicate, BiConsumer insertion_notifier, BiConsumer extraction_notifier) + { inv_ = inv; extraction_predicate_ = extraction_predicate; insertion_predicate_ = insertion_predicate; insertion_notifier_=insertion_notifier; extraction_notifier_=extraction_notifier; slot_map_ = IntStream.range(0, inv.getContainerSize()).boxed().collect(Collectors.toList()); } + + public MappedItemHandler(Container inv, List slot_map, BiPredicate extraction_predicate, BiPredicate insertion_predicate, BiConsumer insertion_notifier, BiConsumer extraction_notifier) + { inv_ = inv; extraction_predicate_ = extraction_predicate; insertion_predicate_ = insertion_predicate; insertion_notifier_=insertion_notifier; extraction_notifier_=extraction_notifier; slot_map_ = slot_map; } + public MappedItemHandler(Container inv, List slot_map, BiPredicate extraction_predicate, BiPredicate insertion_predicate) - { inv_ = inv; extraction_predicate_ = extraction_predicate; insertion_predicate_ = insertion_predicate; slot_map_ = slot_map; } + { this(inv, slot_map, extraction_predicate, insertion_predicate, (i,s)->{}, (i,s)->{}); } public MappedItemHandler(Container inv, BiPredicate extraction_predicate, BiPredicate insertion_predicate) { this(inv, IntStream.range(0, inv.getContainerSize()).boxed().collect(Collectors.toList()), extraction_predicate, insertion_predicate); } @@ -221,6 +228,7 @@ public class Inventories stack.grow(sst.getCount()); inv_.setItem(slot, stack); inv_.setChanged(); + insertion_notifier_.accept(slot, sst); } return ItemStack.EMPTY; } else { @@ -228,10 +236,11 @@ public class Inventories if(simulate) { stack.shrink(limit); } else { - ItemStack diff = stack.split(limit); - diff.grow(sst.getCount()); - inv_.setItem(slot, diff); + final ItemStack diff = stack.split(limit); + sst.grow(diff.getCount()); + inv_.setItem(slot, sst); inv_.setChanged(); + insertion_notifier_.accept(slot, diff); } return stack; } @@ -243,6 +252,7 @@ public class Inventories if(!simulate) { inv_.setItem(slot, ins); inv_.setChanged(); + insertion_notifier_.accept(slot, ins.copy()); } if(stack.isEmpty()) { stack = ItemStack.EMPTY; @@ -252,6 +262,7 @@ public class Inventories if(!simulate) { inv_.setItem(slot, stack.copy()); inv_.setChanged(); + insertion_notifier_.accept(slot, stack.copy()); } return ItemStack.EMPTY; } @@ -272,12 +283,19 @@ public class Inventories } else { stack = inv_.removeItem(slot, Math.min(stack.getCount(), amount)); inv_.setChanged(); + extraction_notifier_.accept(slot, stack.copy()); } return stack; } // Factories -------------------------------------------------------------------------------------------- + public static LazyOptional createGenericHandler(Container inv, BiPredicate extraction_predicate, BiPredicate insertion_predicate, BiConsumer insertion_notifier, BiConsumer extraction_notifier) + { return LazyOptional.of(() -> new MappedItemHandler(inv, extraction_predicate, insertion_predicate, insertion_notifier, extraction_notifier)); } + + public static LazyOptional createGenericHandler(Container inv, BiPredicate extraction_predicate, BiPredicate insertion_predicate, BiConsumer insertion_notifier, BiConsumer extraction_notifier, List slot_map) + { return LazyOptional.of(() -> new MappedItemHandler(inv, slot_map, extraction_predicate, insertion_predicate, insertion_notifier, extraction_notifier)); } + public static LazyOptional createGenericHandler(Container inv, BiPredicate extraction_predicate, BiPredicate insertion_predicate, List slot_map) { return LazyOptional.of(() -> new MappedItemHandler(inv, slot_map, extraction_predicate, insertion_predicate)); }