diff --git a/src/main/java/com/lothrazar/cyclic/base/BlockBase.java b/src/main/java/com/lothrazar/cyclic/base/BlockBase.java index 22f499b64..4d9e56c99 100644 --- a/src/main/java/com/lothrazar/cyclic/base/BlockBase.java +++ b/src/main/java/com/lothrazar/cyclic/base/BlockBase.java @@ -22,6 +22,7 @@ import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; @@ -192,4 +193,16 @@ private static boolean hasCapabilityDir(Direction facing, IWorld world, BlockPos } return false; } + + //for comparators that dont use item inventories + protected int calcRedstoneFromFluid(TileEntity tileEntity) { + IFluidHandler fluid = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null); + if (fluid.getFluidInTank(0).isEmpty()) { + return 0; + } + float cap = fluid.getTankCapacity(0); + float amt = fluid.getFluidInTank(0).getAmount(); + float f = amt / cap; + return MathHelper.floor(f * 14.0F) + 1; + } } diff --git a/src/main/java/com/lothrazar/cyclic/block/crafter/BlockCrafter.java b/src/main/java/com/lothrazar/cyclic/block/crafter/BlockCrafter.java index df27befda..a300a96c2 100644 --- a/src/main/java/com/lothrazar/cyclic/block/crafter/BlockCrafter.java +++ b/src/main/java/com/lothrazar/cyclic/block/crafter/BlockCrafter.java @@ -28,6 +28,7 @@ import net.minecraft.block.BlockState; import net.minecraft.client.gui.ScreenManager; import net.minecraft.inventory.InventoryHelper; +import net.minecraft.inventory.container.Container; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; @@ -42,6 +43,16 @@ public BlockCrafter(Properties properties) { this.setHasGui(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { diff --git a/src/main/java/com/lothrazar/cyclic/block/crafter/TileCrafter.java b/src/main/java/com/lothrazar/cyclic/block/crafter/TileCrafter.java index 42fb5d8ab..782ebfdef 100644 --- a/src/main/java/com/lothrazar/cyclic/block/crafter/TileCrafter.java +++ b/src/main/java/com/lothrazar/cyclic/block/crafter/TileCrafter.java @@ -236,6 +236,7 @@ else if (!itemStacksInGrid.equals(lastRecipeGrid)) { break; } } + this.updateComparatorOutputLevel(); } } } diff --git a/src/main/java/com/lothrazar/cyclic/block/crate/BlockCrate.java b/src/main/java/com/lothrazar/cyclic/block/crate/BlockCrate.java index c51af8bd8..ad97d7d10 100644 --- a/src/main/java/com/lothrazar/cyclic/block/crate/BlockCrate.java +++ b/src/main/java/com/lothrazar/cyclic/block/crate/BlockCrate.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.ScreenManager; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -26,6 +27,16 @@ public BlockCrate(Properties properties) { this.setHasGui(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override public boolean hasTileEntity(BlockState state) { return true; diff --git a/src/main/java/com/lothrazar/cyclic/block/crate/TileCrate.java b/src/main/java/com/lothrazar/cyclic/block/crate/TileCrate.java index e5accef29..a50f69686 100644 --- a/src/main/java/com/lothrazar/cyclic/block/crate/TileCrate.java +++ b/src/main/java/com/lothrazar/cyclic/block/crate/TileCrate.java @@ -33,6 +33,7 @@ public ITextComponent getDisplayName() { @Override public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity playerEntity) { + this.updateComparatorOutputLevel(); return new ContainerCrate(i, world, pos, playerInventory, playerEntity); } diff --git a/src/main/java/com/lothrazar/cyclic/block/dice/TileDice.java b/src/main/java/com/lothrazar/cyclic/block/dice/TileDice.java index 22f2a9c38..133a47b51 100644 --- a/src/main/java/com/lothrazar/cyclic/block/dice/TileDice.java +++ b/src/main/java/com/lothrazar/cyclic/block/dice/TileDice.java @@ -55,29 +55,8 @@ public void tick() { BlockState stateold = world.getBlockState(pos); BlockState newstate = stateold.with(BlockStateProperties.FACING, fac); world.setBlockState(pos, newstate); - // world.notifyBlockUpdate(pos, stateold, newstate, 3); } } - // - // - // @Override - // public void update() { - // if (this.timer == 0) { - // this.spinningIfZero = 1; - // world.updateComparatorOutputLevel(pos, this.blockType); - // } - // else { - // this.timer--; - // //toggle block state - // if (this.timer % TICKS_PER_CHANGE == 0) { - // this.spinningIfZero = 0; - // EnumFacing fac = UtilDirection.getRandom(world.rand); - // IBlockState stateold = world.getBlockState(pos); - // IBlockState newstate = stateold.withProperty(BlockDice.PROPERTYFACING, fac); - // world.setBlockState(pos, newstate); - // // world.notifyBlockUpdate(pos, stateold, newstate, 3); - // } - // } } @Override diff --git a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java index 78cabbfda..204c07125 100644 --- a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java +++ b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java @@ -14,6 +14,7 @@ import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; public class BlockFluidHopper extends BlockBase { @@ -24,6 +25,16 @@ public BlockFluidHopper(Properties properties) { this.setHasFluidInteract(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return calcRedstoneFromFluid(worldIn.getTileEntity(pos)); + } + @Override public void registerClient() { // RenderTypeLookup.setRenderLayer(this, RenderType.getTranslucent()); diff --git a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java index c89d3040a..48c5ccf79 100644 --- a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java +++ b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java @@ -79,11 +79,13 @@ private void tryExtract(Direction extractSide) { if (stuff != null) { success = UtilFluid.tryFillPositionFromTank(world, pos, extractSide, stuff, FLOW); if (success) { + this.updateComparatorOutputLevel(); return; } } if (!success && tank.getSpace() >= FluidAttributes.BUCKET_VOLUME) { UtilFluid.extractSourceWaterloggedCauldron(world, target, tank); + this.updateComparatorOutputLevel(); } } diff --git a/src/main/java/com/lothrazar/cyclic/block/hoppergold/BlockGoldHopper.java b/src/main/java/com/lothrazar/cyclic/block/hoppergold/BlockGoldHopper.java index 813a8c897..0dc5efeb0 100644 --- a/src/main/java/com/lothrazar/cyclic/block/hoppergold/BlockGoldHopper.java +++ b/src/main/java/com/lothrazar/cyclic/block/hoppergold/BlockGoldHopper.java @@ -2,8 +2,11 @@ import com.lothrazar.cyclic.block.hopper.BlockSimpleHopper; import net.minecraft.block.BlockState; +import net.minecraft.inventory.container.Container; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; public class BlockGoldHopper extends BlockSimpleHopper { @@ -11,6 +14,16 @@ public BlockGoldHopper(Properties properties) { super(properties.hardnessAndResistance(1.3F)); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new TileGoldHopper(); diff --git a/src/main/java/com/lothrazar/cyclic/block/melter/BlockMelter.java b/src/main/java/com/lothrazar/cyclic/block/melter/BlockMelter.java index c96590d91..839dbe7e6 100644 --- a/src/main/java/com/lothrazar/cyclic/block/melter/BlockMelter.java +++ b/src/main/java/com/lothrazar/cyclic/block/melter/BlockMelter.java @@ -9,12 +9,14 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.fluid.FluidState; +import net.minecraft.inventory.container.Container; import net.minecraft.state.StateContainer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockDisplayReader; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; import net.minecraftforge.common.ToolType; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -25,6 +27,16 @@ public BlockMelter(Properties properties) { this.setHasGui(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override @Deprecated public float getAmbientOcclusionLightValue(BlockState state, IBlockReader worldIn, BlockPos pos) { diff --git a/src/main/java/com/lothrazar/cyclic/block/melter/TileMelter.java b/src/main/java/com/lothrazar/cyclic/block/melter/TileMelter.java index a00fcd6cd..180d7f196 100644 --- a/src/main/java/com/lothrazar/cyclic/block/melter/TileMelter.java +++ b/src/main/java/com/lothrazar/cyclic/block/melter/TileMelter.java @@ -211,6 +211,7 @@ private boolean tryProcessRecipe() { inventory.getStackInSlot(0).shrink(1); inventory.getStackInSlot(1).shrink(1); tank.fill(this.currentRecipe.getRecipeFluid(), FluidAction.EXECUTE); + updateComparatorOutputLevel(); return true; } return false; diff --git a/src/main/java/com/lothrazar/cyclic/block/packager/BlockPackager.java b/src/main/java/com/lothrazar/cyclic/block/packager/BlockPackager.java index 846d2b9e9..73cdc347a 100644 --- a/src/main/java/com/lothrazar/cyclic/block/packager/BlockPackager.java +++ b/src/main/java/com/lothrazar/cyclic/block/packager/BlockPackager.java @@ -7,10 +7,13 @@ import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; +import net.minecraft.inventory.container.Container; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; public class BlockPackager extends BlockBase { @@ -19,6 +22,16 @@ public BlockPackager(Properties properties) { this.setHasGui(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override protected void fillStateContainer(StateContainer.Builder builder) { builder.add(BlockStateProperties.FACING).add(LIT); diff --git a/src/main/java/com/lothrazar/cyclic/block/packager/TilePackager.java b/src/main/java/com/lothrazar/cyclic/block/packager/TilePackager.java index b9e4606dd..18772bf16 100644 --- a/src/main/java/com/lothrazar/cyclic/block/packager/TilePackager.java +++ b/src/main/java/com/lothrazar/cyclic/block/packager/TilePackager.java @@ -97,6 +97,7 @@ private void tryDoPackage() { inputSlots.extractItem(0, total, false); outputSlots.insertItem(0, output, false); energy.extractEnergy(POWERCONF.get(), false); + this.updateComparatorOutputLevel(); } } diff --git a/src/main/java/com/lothrazar/cyclic/block/placer/BlockPlacer.java b/src/main/java/com/lothrazar/cyclic/block/placer/BlockPlacer.java index 240293314..e0f526011 100644 --- a/src/main/java/com/lothrazar/cyclic/block/placer/BlockPlacer.java +++ b/src/main/java/com/lothrazar/cyclic/block/placer/BlockPlacer.java @@ -7,6 +7,7 @@ import net.minecraft.block.BlockState; import net.minecraft.client.gui.ScreenManager; import net.minecraft.entity.LivingEntity; +import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; @@ -22,6 +23,16 @@ public BlockPlacer(Properties properties) { this.setHasGui(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override public void registerClient() { ScreenManager.registerFactory(ContainerScreenRegistry.placer, ScreenPlacer::new); diff --git a/src/main/java/com/lothrazar/cyclic/block/placer/TilePlacer.java b/src/main/java/com/lothrazar/cyclic/block/placer/TilePlacer.java index 254b2fd99..2db5d7004 100644 --- a/src/main/java/com/lothrazar/cyclic/block/placer/TilePlacer.java +++ b/src/main/java/com/lothrazar/cyclic/block/placer/TilePlacer.java @@ -56,9 +56,9 @@ public void tick() { Direction dir = this.getBlockState().get(BlockStateProperties.FACING); BlockPos offset = pos.offset(dir); BlockState state = Block.getBlockFromItem(stack.getItem()).getDefaultState(); - if (world.isAirBlock(offset) && - world.setBlockState(offset, state)) { + if (world.isAirBlock(offset) && world.setBlockState(offset, state)) { stack.shrink(1); + this.updateComparatorOutputLevel(); } } diff --git a/src/main/java/com/lothrazar/cyclic/block/solidifier/BlockSolidifier.java b/src/main/java/com/lothrazar/cyclic/block/solidifier/BlockSolidifier.java index 4dadb2fff..14e5d9774 100644 --- a/src/main/java/com/lothrazar/cyclic/block/solidifier/BlockSolidifier.java +++ b/src/main/java/com/lothrazar/cyclic/block/solidifier/BlockSolidifier.java @@ -9,12 +9,14 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.fluid.FluidState; +import net.minecraft.inventory.container.Container; import net.minecraft.state.StateContainer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockDisplayReader; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; import net.minecraftforge.common.ToolType; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -26,6 +28,16 @@ public BlockSolidifier(Properties properties) { this.setHasFluidInteract(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return Container.calcRedstone(worldIn.getTileEntity(pos)); + } + @Override @Deprecated public float getAmbientOcclusionLightValue(BlockState state, IBlockReader worldIn, BlockPos pos) { diff --git a/src/main/java/com/lothrazar/cyclic/block/solidifier/TileSolidifier.java b/src/main/java/com/lothrazar/cyclic/block/solidifier/TileSolidifier.java index 3f66a5c3c..adcf674ab 100644 --- a/src/main/java/com/lothrazar/cyclic/block/solidifier/TileSolidifier.java +++ b/src/main/java/com/lothrazar/cyclic/block/solidifier/TileSolidifier.java @@ -205,6 +205,7 @@ private boolean tryProcessRecipe() { inputSlots.getStackInSlot(2).shrink(1); tank.drain(this.currentRecipe.fluidIngredient.getAmount(), FluidAction.EXECUTE); outputSlots.insertItem(0, currentRecipe.getRecipeOutput(), false); + updateComparatorOutputLevel(); return true; } ModCyclic.LOGGER.info(pos + " recipe stop on fluid not enoughl"); diff --git a/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java b/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java index d57be639e..c802e1058 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java +++ b/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java @@ -45,6 +45,16 @@ public BlockFluidTank(Properties properties) { this.setHasFluidInteract(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return calcRedstoneFromFluid(worldIn.getTileEntity(pos)); + } + @Override public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { if (!player.isCrouching() && player.getHeldItem(hand).getItem() == this.asItem() diff --git a/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java b/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java index 1d81ddd7c..9b1af7e8a 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java +++ b/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java @@ -49,6 +49,7 @@ public LazyOptional getCapability(Capability cap, Direction side) { return super.getCapability(cap, side); } + @Override public void invalidateCaps() { fluidCap.invalidate(); super.invalidateCaps(); @@ -65,6 +66,7 @@ public int getField(int field) { @Override public void setFluid(FluidStack fluid) { tank.setFluid(fluid); + this.updateComparatorOutputLevel(); } @Override diff --git a/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java b/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java index c273b0bab..e93d586a8 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java +++ b/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java @@ -28,6 +28,16 @@ public BlockCask(Properties properties) { this.setHasFluidInteract(); } + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { + return calcRedstoneFromFluid(worldIn.getTileEntity(pos)); + } + @Override public boolean hasTileEntity(BlockState state) { return true; diff --git a/update.json b/update.json index 96d83aba7..ae61720ab 100644 --- a/update.json +++ b/update.json @@ -81,6 +81,6 @@ ,"1.5.22":"Fix #2351 advanced crafting stick not opening. " ,"1.5.23":"Growth enchantment now uses the same logic as Sprinkler & Terra Soil (only minecraft:crops or minecraft::saplings can grow, respect IGrowable::canUseBonemeal). New gloomIgnored config Gloom enchant (cyclic:curse) to ignore and not use these effects #2217 #2325. Fix Soundproofing block not muting Mekanism sounds #2389 (for example Precision Sawmill and others - you may need four or more soundproofing blocks for the desired effect). Patch an edge-case where User might drop items on the ground. New config [cyclic.blocks.soundproofing] radius = 6 to control the area. Fix item cable routing #2245 #2230. New config under [cyclic.blocks] wireless_transfer_dimensional = true allowing transfer nodes to connect across dimensions #1913. Balance recipe changes for #2372. Balance changes made for Excavate enchant it will no longer trigger if the tool is not 'mineable' effective for example axe on dirt. New feature for Excavate enchant #2116 it will not trigger on anything matching the block data-tag 'cyclic:ignored/excavate'. [Backported changes from mc1.20.1] #2182 candle model assets; Block Breaker no longer tries (and fails) to mine liquid source blocks; Block Randomizer use wireframe rendering only of non-air instead of solid shading; Glistering & Corrupted chorus only restores 1 food-unit down from 3; a few recipes tweaked/backported to match mc1.20.1+, ported crafttweaker zenscript support for generator_fluid and generator_item; backported item data tags for use in recipes for example forge:vines, forge:sandstone, forge:mushrooms " ,"1.5.24":"Fixed bug in the item cyclic:offset_scepter #2427. Tweaked block model visuals of the Transfer Nodes. Fix Mattock not saving contents of Shulker Boxes when mined #2411. " - ,"":"Some blocks allow minecraft:comparator to pull a redstone signal based on inventory contents: Wooden Hopper, Item Collector, Forester, Item Shelf, . Fluid collector will now place air and scoop up the fluid if the itemslot is empty. New feature: some machines can now be placed facing Up or Down vertically for convenience (harvester, forester, miner, item collector, fluid collector, dropper). Backported machine feature 'Preview Outline' mode on machines that already have the button. Backported cable (fluid & energy) buffer and flow speed configs from 1.20.1 " + ,"":"Many blocks now allow minecraft:comparator to pull a redstone signal based on inventory contents. Fluid collector will now place air and scoop up the fluid if the itemslot is empty. New feature: some machines can now be placed facing Up or Down vertically for convenience (harvester, forester, miner, item collector, fluid collector, dropper). Backported machine feature 'Preview Outline' mode on machines that already have the button. Backported cable (fluid & energy) buffer and flow speed configs from 1.20.1 " } }