diff --git a/examples/config/cyclic.toml b/examples/config/cyclic.toml index 8dd8af938..a284e6fe4 100644 --- a/examples/config/cyclic.toml +++ b/examples/config/cyclic.toml @@ -505,6 +505,16 @@ #Range: 1 ~ 128 radius = 16 + [cyclic.blocks.facades] + # + # These blocks are not allowed to be used as Facades for blocks because they look weird (used by cables and Glowstone Facade and Soundproofing Facade and others) + itemsNotAllowed = ["minecraft:ladder", "minecraft:double_plant", "minecraft:waterlily", "minecraft:torch", "minecraft:*_torch", "minecraft:redstone", "minecraft:iron_bars", "minecraft:chest", "minecraft:ender_chest", "minecraft:sculk_vein", "minecraft:string", "minecraft:vine", "minecraft:rail", "minecraft:*_rail", "minecraft:brewing_stand", "minecraft:*_dripleaf", "minecraft:*_pane", "minecraft:*_sapling", "minecraft:*_sign", "minecraft:*_door", "minecraft:*_banner", "minecraft:*_shulker_box", "cyclic:*_pipe", "cyclic:*_bars", "storagenetwork:*"] + + [cyclic.blocks.facades.cables] + # + # Allow cables to have blocks placed in them as facades (sneak-left-click to set; use empty hand to remove). Set to false to disable facades + enabled = true + [cyclic.blocks.user] #Power per use user #Range: 0 ~ 64000 diff --git a/src/main/java/com/lothrazar/cyclic/block/BlockCyclic.java b/src/main/java/com/lothrazar/cyclic/block/BlockCyclic.java index 4f5c8c081..ab3a783ac 100644 --- a/src/main/java/com/lothrazar/cyclic/block/BlockCyclic.java +++ b/src/main/java/com/lothrazar/cyclic/block/BlockCyclic.java @@ -203,4 +203,16 @@ private static boolean hasCapabilityDir(Direction facing, LevelAccessor world, B } return false; } + + //for comparators that dont use item inventories + protected int calcRedstoneFromFluid(BlockEntity tileEntity) { + IFluidHandler fluid = tileEntity.getCapability(ForgeCapabilities.FLUID_HANDLER).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 (int) Math.floor((f * 14.0F)) + 1; + } } diff --git a/src/main/java/com/lothrazar/cyclic/block/TileBlockEntityCyclic.java b/src/main/java/com/lothrazar/cyclic/block/TileBlockEntityCyclic.java index cf5e7c229..0c1d26da0 100644 --- a/src/main/java/com/lothrazar/cyclic/block/TileBlockEntityCyclic.java +++ b/src/main/java/com/lothrazar/cyclic/block/TileBlockEntityCyclic.java @@ -704,4 +704,8 @@ public void updateComparatorOutputLevel() { //was updateComparatorOutputLevel() level.updateNeighbourForOutputSignal(worldPosition, this.getBlockState().getBlock()); } + + public void updateComparatorOutputLevelAt(BlockPos target) { + level.updateNeighbourForOutputSignal(target, level.getBlockState(target).getBlock()); + } } diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/CableBase.java b/src/main/java/com/lothrazar/cyclic/block/cable/CableBase.java index 009be4da5..05d1eb716 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/CableBase.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/CableBase.java @@ -3,6 +3,7 @@ import java.util.Map; import com.google.common.collect.Maps; import com.lothrazar.cyclic.block.BlockCyclic; +import com.lothrazar.cyclic.block.facade.IBlockFacade; import com.lothrazar.cyclic.data.DataTags; import com.lothrazar.cyclic.registry.BlockRegistry; import com.lothrazar.cyclic.registry.SoundRegistry; @@ -35,7 +36,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; import net.minecraftforge.network.NetworkHooks; -public abstract class CableBase extends BlockCyclic implements SimpleWaterloggedBlock { +public abstract class CableBase extends BlockCyclic implements SimpleWaterloggedBlock, IBlockFacade { public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; //regular connections diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/TileCableBase.java b/src/main/java/com/lothrazar/cyclic/block/cable/TileCableBase.java new file mode 100644 index 000000000..0e776b2c8 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/cable/TileCableBase.java @@ -0,0 +1,39 @@ +package com.lothrazar.cyclic.block.cable; + +import com.lothrazar.cyclic.block.TileBlockEntityCyclic; +import com.lothrazar.cyclic.block.facade.ITileFacade; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +public abstract class TileCableBase extends TileBlockEntityCyclic implements ITileFacade { + + public TileCableBase(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + super(tileEntityTypeIn, pos, state); + } + + @Override + public void load(CompoundTag tag) { + this.loadFacade(tag); + super.load(tag); + } + + @Override + public void saveAdditional(CompoundTag tag) { + this.saveFacade(tag); + super.saveAdditional(tag); + } + + private CompoundTag facadeState = null; + + @Override + public CompoundTag getFacade() { + return facadeState; + } + + @Override + public void setFacade(CompoundTag facadeState) { + this.facadeState = facadeState; + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/energy/BlockCableEnergy.java b/src/main/java/com/lothrazar/cyclic/block/cable/energy/BlockCableEnergy.java index 81ef415fe..480b61bc6 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/energy/BlockCableEnergy.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/energy/BlockCableEnergy.java @@ -3,6 +3,7 @@ import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; import com.lothrazar.cyclic.block.cable.ShapeCache; +import com.lothrazar.cyclic.config.ConfigRegistry; import com.lothrazar.cyclic.registry.TileRegistry; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -31,6 +32,12 @@ public BlockCableEnergy(Properties properties) { @Override public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + if (ConfigRegistry.CABLE_FACADES.get()) { + VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context); + if (facade != null) { + return facade; + } + } return ShapeCache.getOrCreate(state, CableBase::createShape); } diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/energy/TileCableEnergy.java b/src/main/java/com/lothrazar/cyclic/block/cable/energy/TileCableEnergy.java index 54a06d995..7dd842835 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/energy/TileCableEnergy.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/energy/TileCableEnergy.java @@ -3,9 +3,9 @@ import java.util.Map; import com.google.common.collect.Maps; import com.lothrazar.cyclic.ModCyclic; -import com.lothrazar.cyclic.block.TileBlockEntityCyclic; import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; +import com.lothrazar.cyclic.block.cable.TileCableBase; import com.lothrazar.cyclic.capabilities.block.CustomEnergyStorage; import com.lothrazar.cyclic.registry.TileRegistry; import com.lothrazar.cyclic.util.UtilDirection; @@ -22,7 +22,7 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.IEnergyStorage; -public class TileCableEnergy extends TileBlockEntityCyclic { +public class TileCableEnergy extends TileCableBase { final CustomEnergyStorage energy; private LazyOptional energyCap; diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/fluid/BlockCableFluid.java b/src/main/java/com/lothrazar/cyclic/block/cable/fluid/BlockCableFluid.java index 1b4685af6..40eb163e4 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/fluid/BlockCableFluid.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/fluid/BlockCableFluid.java @@ -4,6 +4,7 @@ import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; import com.lothrazar.cyclic.block.cable.ShapeCache; +import com.lothrazar.cyclic.config.ConfigRegistry; import com.lothrazar.cyclic.registry.MenuTypeRegistry; import com.lothrazar.cyclic.registry.TileRegistry; import net.minecraft.ChatFormatting; @@ -55,6 +56,12 @@ public void registerClient() { @Override public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + if (ConfigRegistry.CABLE_FACADES.get()) { + VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context); + if (facade != null) { + return facade; + } + } return ShapeCache.getOrCreate(state, CableBase::createShape); } diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/fluid/TileCableFluid.java b/src/main/java/com/lothrazar/cyclic/block/cable/fluid/TileCableFluid.java index 66e4a321d..990a97d45 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/fluid/TileCableFluid.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/fluid/TileCableFluid.java @@ -5,9 +5,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.IntStream; -import com.lothrazar.cyclic.block.TileBlockEntityCyclic; import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; +import com.lothrazar.cyclic.block.cable.TileCableBase; import com.lothrazar.cyclic.capabilities.block.FluidTankBase; import com.lothrazar.cyclic.item.datacard.filter.FilterCardItem; import com.lothrazar.cyclic.registry.BlockRegistry; @@ -36,7 +36,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.ItemStackHandler; -public class TileCableFluid extends TileBlockEntityCyclic implements MenuProvider { +public class TileCableFluid extends TileCableBase implements MenuProvider { public static IntValue BUFFERSIZE; public static IntValue TRANSFER_RATE; diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/item/BlockCableItem.java b/src/main/java/com/lothrazar/cyclic/block/cable/item/BlockCableItem.java index 95f399183..7cc94b22d 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/item/BlockCableItem.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/item/BlockCableItem.java @@ -3,6 +3,7 @@ import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; import com.lothrazar.cyclic.block.cable.ShapeCache; +import com.lothrazar.cyclic.config.ConfigRegistry; import com.lothrazar.cyclic.registry.MenuTypeRegistry; import com.lothrazar.cyclic.registry.TileRegistry; import net.minecraft.client.gui.screens.MenuScreens; @@ -39,6 +40,12 @@ public void registerClient() { @Override public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + if (ConfigRegistry.CABLE_FACADES.get()) { + VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context); + if (facade != null) { + return facade; + } + } return ShapeCache.getOrCreate(state, CableBase::createShape); } diff --git a/src/main/java/com/lothrazar/cyclic/block/cable/item/TileCableItem.java b/src/main/java/com/lothrazar/cyclic/block/cable/item/TileCableItem.java index 2e9da5b18..cd9963acd 100644 --- a/src/main/java/com/lothrazar/cyclic/block/cable/item/TileCableItem.java +++ b/src/main/java/com/lothrazar/cyclic/block/cable/item/TileCableItem.java @@ -2,9 +2,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import com.lothrazar.cyclic.block.TileBlockEntityCyclic; import com.lothrazar.cyclic.block.cable.CableBase; import com.lothrazar.cyclic.block.cable.EnumConnectType; +import com.lothrazar.cyclic.block.cable.TileCableBase; import com.lothrazar.cyclic.registry.BlockRegistry; import com.lothrazar.cyclic.registry.ItemRegistry; import com.lothrazar.cyclic.registry.TileRegistry; @@ -28,7 +28,7 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; -public class TileCableItem extends TileBlockEntityCyclic implements MenuProvider { +public class TileCableItem extends TileCableBase implements MenuProvider { private static final int FLOW_QTY = 64; // fixed, for non-extract motion private int extractQty = FLOW_QTY; // default diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/IBlockFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/IBlockFacade.java new file mode 100644 index 000000000..4e84c2547 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/IBlockFacade.java @@ -0,0 +1,42 @@ +package com.lothrazar.cyclic.block.facade; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public interface IBlockFacade { + + default VoxelShape getFacadeShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext ctx) { + BlockState tfs = getFacadeState(state, level, pos); + if (tfs != null && tfs.getBlock() != state.getBlock()) { + return ctx == null ? tfs.getShape(level, pos) : tfs.getShape(level, pos, ctx); + } + return null; + } + + default BlockState getFacadeState(BlockState state, BlockGetter level, BlockPos pos) { + if (level == null) { + return null; + } + ITileFacade tile = this.getTileFacade(level, pos); + if (tile != null && level instanceof Level lvl) { + return tile.getFacadeState(lvl); + } + return null; + } + + default ITileFacade getTileFacade(BlockGetter level, BlockPos pos) { + if (level == null) { + return null; + } + BlockEntity tile = level.getBlockEntity(pos); + if (tile instanceof ITileFacade) { + return (ITileFacade) tile; + } + return null; + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/ITileFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/ITileFacade.java new file mode 100644 index 000000000..3d54f609c --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/ITileFacade.java @@ -0,0 +1,43 @@ +package com.lothrazar.cyclic.block.facade; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; + +public interface ITileFacade { + + public static final String NBT_FACADE = "facade"; + + CompoundTag getFacade(); + + void setFacade(CompoundTag facadeState); + + default BlockState getFacadeState(Level level) { + CompoundTag facadeState = getFacade(); + if (level == null || facadeState == null || facadeState.isEmpty()) { + return null; // level is null on world load + } + BlockState stateFound = NbtUtils.readBlockState(facadeState); + return stateFound; + } + + default void loadFacade(CompoundTag compound) { + if (compound.contains(NBT_FACADE)) { + this.setFacade(compound.getCompound(NBT_FACADE)); + } + else { + this.setFacade(null); + } + } + + default void saveFacade(CompoundTag compound) { + CompoundTag facadeState = getFacade(); + if (facadeState == null) { + compound.remove(NBT_FACADE); + } + else { + compound.put(NBT_FACADE, facadeState); + } + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/RenderCableFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/RenderCableFacade.java new file mode 100644 index 000000000..d946e5b87 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/RenderCableFacade.java @@ -0,0 +1,37 @@ +package com.lothrazar.cyclic.block.facade; + +import com.lothrazar.cyclic.block.cable.TileCableBase; +import com.lothrazar.cyclic.config.ConfigRegistry; +import com.lothrazar.cyclic.util.FacadeUtil; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.state.BlockState; + +public class RenderCableFacade implements BlockEntityRenderer { + + private BlockRenderDispatcher brd; + private ModelBlockRenderer renderer; + + public RenderCableFacade(BlockEntityRendererProvider.Context d) { + this.brd = d.getBlockRenderDispatcher(); + this.renderer = brd.getModelRenderer(); + } + + @Override + public boolean shouldRenderOffScreen(TileCableBase te) { + return true; + } + + @Override + public void render(TileCableBase te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) { + if (te.getFacade() != null + && ConfigRegistry.CABLE_FACADES.get()) { + BlockState facadeState = te.getFacadeState(te.getLevel()); + FacadeUtil.renderBlockState(te.getLevel(), te.getBlockPos(), brd, renderer, ibuffer, matrixStack, facadeState, packedLight, packedOverlay); + } + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/light/BlockLightFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/light/BlockLightFacade.java new file mode 100644 index 000000000..a46a534a3 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/light/BlockLightFacade.java @@ -0,0 +1,40 @@ +package com.lothrazar.cyclic.block.facade.light; + +import com.lothrazar.cyclic.block.BlockCyclic; +import com.lothrazar.cyclic.block.facade.IBlockFacade; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class BlockLightFacade extends BlockCyclic implements IBlockFacade { + + private static final VoxelShape THREE = Block.box(6, 6, 6, + 10, 10, 10); + + public BlockLightFacade(Properties properties) { + super(properties.lightLevel(state -> 15).strength(1F).noOcclusion()); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { // ISelectionContext + VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context); + if (facade != null) { + return facade; + } + return THREE; + } + + @Override + public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { + return true; + } + + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new TileLightFacade(pos, state); + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/light/RenderLightFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/light/RenderLightFacade.java new file mode 100644 index 000000000..e4c91aa47 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/light/RenderLightFacade.java @@ -0,0 +1,34 @@ +package com.lothrazar.cyclic.block.facade.light; + +import com.lothrazar.cyclic.util.FacadeUtil; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.state.BlockState; + +public class RenderLightFacade implements BlockEntityRenderer { + + private BlockRenderDispatcher brd; + private ModelBlockRenderer renderer; + + public RenderLightFacade(BlockEntityRendererProvider.Context d) { + this.brd = d.getBlockRenderDispatcher(); + this.renderer = brd.getModelRenderer(); + } + + @Override + public boolean shouldRenderOffScreen(TileLightFacade te) { + return true; + } + + @Override + public void render(TileLightFacade te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) { + if (te.getFacade() != null) { + BlockState facadeState = te.getFacadeState(te.getLevel()); + FacadeUtil.renderBlockState(te.getLevel(), te.getBlockPos(), brd, renderer, ibuffer, matrixStack, facadeState, packedLight, packedOverlay); + } + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/light/TileLightFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/light/TileLightFacade.java new file mode 100644 index 000000000..043138850 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/light/TileLightFacade.java @@ -0,0 +1,62 @@ +package com.lothrazar.cyclic.block.facade.light; + +import java.util.ArrayList; +import java.util.List; +import com.lothrazar.cyclic.block.TileBlockEntityCyclic; +import com.lothrazar.cyclic.block.facade.ITileFacade; +import com.lothrazar.cyclic.registry.TileRegistry; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; + +public class TileLightFacade extends TileBlockEntityCyclic implements ITileFacade { + + public TileLightFacade(BlockPos pos, BlockState state) { + super(TileRegistry.LIGHT_CAMO.get(), pos, state); + } + + @Override + public void load(CompoundTag tag) { + super.load(tag); + this.loadFacade(tag); + } + + @Override + public void saveAdditional(CompoundTag tag) { + this.saveFacade(tag); + super.saveAdditional(tag); + } + + @Override + public AABB getRenderBoundingBox() { + return BlockEntity.INFINITE_EXTENT_AABB; + } + + @Override + public void setField(int field, int value) {} + + @Override + public int getField(int field) { + return 0; + } + + public List getShape() { + List lis = new ArrayList(); + lis.add(worldPosition); + return lis; + } + + private CompoundTag facadeState = null; + + @Override + public CompoundTag getFacade() { + return facadeState; + } + + @Override + public void setFacade(CompoundTag facadeState) { + this.facadeState = facadeState; + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffRender.java b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffRender.java new file mode 100644 index 000000000..bb38a82d8 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffRender.java @@ -0,0 +1,34 @@ +package com.lothrazar.cyclic.block.facade.soundmuff; + +import com.lothrazar.cyclic.util.FacadeUtil; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.state.BlockState; + +public class SoundmuffRender implements BlockEntityRenderer { + + private BlockRenderDispatcher brd; + private ModelBlockRenderer renderer; + + public SoundmuffRender(BlockEntityRendererProvider.Context d) { + this.brd = d.getBlockRenderDispatcher(); + this.renderer = brd.getModelRenderer(); + } + + @Override + public boolean shouldRenderOffScreen(SoundmuffTileFacade te) { + return true; + } + + @Override + public void render(SoundmuffTileFacade te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) { + if (te.getFacade() != null) { + BlockState facadeState = te.getFacadeState(te.getLevel()); + FacadeUtil.renderBlockState(te.getLevel(), te.getBlockPos(), brd, renderer, ibuffer, matrixStack, facadeState, packedLight, packedOverlay); + } + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffTileFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffTileFacade.java new file mode 100644 index 000000000..1ea59b227 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmuffTileFacade.java @@ -0,0 +1,62 @@ +package com.lothrazar.cyclic.block.facade.soundmuff; + +import java.util.ArrayList; +import java.util.List; +import com.lothrazar.cyclic.block.TileBlockEntityCyclic; +import com.lothrazar.cyclic.block.facade.ITileFacade; +import com.lothrazar.cyclic.registry.TileRegistry; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; + +public class SoundmuffTileFacade extends TileBlockEntityCyclic implements ITileFacade { + + public SoundmuffTileFacade(BlockPos pos, BlockState state) { + super(TileRegistry.SOUNDPROOFING_GHOST.get(), pos, state); + } + + @Override + public void load(CompoundTag tag) { + this.loadFacade(tag); + super.load(tag); + } + + @Override + public void saveAdditional(CompoundTag tag) { + this.saveFacade(tag); + super.saveAdditional(tag); + } + + @Override + public AABB getRenderBoundingBox() { + return BlockEntity.INFINITE_EXTENT_AABB; + } + + @Override + public void setField(int field, int value) {} + + @Override + public int getField(int field) { + return 0; + } + + public List getShape() { + List lis = new ArrayList(); + lis.add(worldPosition); + return lis; + } + + private CompoundTag facadeState = null; + + @Override + public CompoundTag getFacade() { + return facadeState; + } + + @Override + public void setFacade(CompoundTag facadeState) { + this.facadeState = facadeState; + } +} diff --git a/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmufflerBlockFacade.java b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmufflerBlockFacade.java new file mode 100644 index 000000000..651b00527 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/block/facade/soundmuff/SoundmufflerBlockFacade.java @@ -0,0 +1,35 @@ +package com.lothrazar.cyclic.block.facade.soundmuff; + +import com.lothrazar.cyclic.block.facade.IBlockFacade; +import com.lothrazar.cyclic.block.soundmuff.SoundmufflerBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class SoundmufflerBlockFacade extends SoundmufflerBlock implements IBlockFacade { + + private static final VoxelShape THREE = Block.box(6, 6, 6, + 10, 10, 10); + + public SoundmufflerBlockFacade(Properties properties) { + super(properties.noOcclusion()); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context); + if (facade != null) { + return facade; + } + return THREE; + } + + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new SoundmuffTileFacade(pos, state); + } +} 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 e61ada25a..51bff0aa9 100644 --- a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java +++ b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/BlockFluidHopper.java @@ -5,7 +5,6 @@ import com.lothrazar.cyclic.registry.TileRegistry; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -36,13 +35,7 @@ public boolean hasAnalogOutputSignal(BlockState bs) { @Override public int getAnalogOutputSignal(BlockState st, Level level, BlockPos pos) { - return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); - } - - @Override - public void registerClient() { - // RenderTypeLookup.setRenderLayer(this, RenderType.getTranslucent()); - // ClientRegistry.bindTileEntityRenderer(TileRegistry.FLUIDHOPPER.get(), RenderHopperFluid::new); + return calcRedstoneFromFluid(level.getBlockEntity(pos)); } @Override 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 92a2121e8..26a7c2d4f 100644 --- a/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java +++ b/src/main/java/com/lothrazar/cyclic/block/hopperfluid/TileFluidHopper.java @@ -74,6 +74,8 @@ public void tick() { Direction exportToSide = this.getBlockState().getValue(BlockFluidHopper.FACING); if (exportToSide != null && exportToSide != Direction.UP) { moveFluids(exportToSide, worldPosition.relative(exportToSide), FLOW, tank); + this.updateComparatorOutputLevel(); + this.updateComparatorOutputLevelAt(worldPosition.relative(exportToSide)); } } @@ -85,6 +87,7 @@ private void tryExtract() { IFluidHandler tankAbove = FluidHelpers.getTank(level, target, Direction.DOWN); boolean success = FluidHelpers.tryFillPositionFromTank(level, worldPosition, Direction.UP, tankAbove, FLOW); if (success) { + this.updateComparatorOutputLevelAt(target); this.updateComparatorOutputLevel(); return; } diff --git a/src/main/java/com/lothrazar/cyclic/block/lightcompr/BlockLightCamo.java b/src/main/java/com/lothrazar/cyclic/block/lightcompr/BlockLightCamo.java deleted file mode 100644 index 11f30cdbb..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/lightcompr/BlockLightCamo.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.lothrazar.cyclic.block.lightcompr; - -import com.lothrazar.cyclic.block.BlockCyclic; -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; - -public class BlockLightCamo extends BlockCyclic { - - public BlockLightCamo(Properties properties) { - super(properties.lightLevel(state -> 15).strength(1F).noOcclusion()); - } - - @Override - public void registerClient() {} - - @Override - public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { - return true; - } - - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return new TileLightCamo(pos, state); - } - - // @Override - // public BlockEntityTicker getTicker(Level world, BlockState state, BlockEntityType type) { - // return createTickerHelper(type, TileRegistry.light_camo, world.isClientSide ? TileLightCamo::clientTick : TileLightCamo::serverTick); - // } - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { - ItemStack stack = player.getItemInHand(handIn); - TileLightCamo ent = (TileLightCamo) world.getBlockEntity(pos); - if (stack.isEmpty() && handIn == InteractionHand.MAIN_HAND) { - //try to pull - ItemStack extracted = ent.notInventory.extractItem(0, 64, false); - if (!extracted.isEmpty()) { - //drop it - player.drop(extracted, true); - } - } - if (Block.byItem(stack.getItem()) == null) { - return super.use(state, world, pos, player, handIn, hit); - } - //replace it - if (!ent.notInventory.getStackInSlot(0).isEmpty()) { - //noempty so drop it first - ItemStack pulled = ent.notInventory.extractItem(0, 64, false); - player.drop(pulled, true); - } - //is it empty so now just replace every time - ItemStack copy = new ItemStack(stack.getItem(), 1); - ItemStack insertRemainder = ent.notInventory.insertItem(0, copy, false); - //success means no remainder, it took 1 - if (insertRemainder.isEmpty()) { - stack.shrink(1); //eat it!!! - return InteractionResult.SUCCESS; - } - //else do we nuke it? - // - return super.use(state, world, pos, player, handIn, hit); - } -} diff --git a/src/main/java/com/lothrazar/cyclic/block/lightcompr/RenderLightCamo.java b/src/main/java/com/lothrazar/cyclic/block/lightcompr/RenderLightCamo.java deleted file mode 100644 index 27f64b428..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/lightcompr/RenderLightCamo.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.lothrazar.cyclic.block.lightcompr; - -import com.lothrazar.cyclic.render.RenderUtils; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; - -public class RenderLightCamo implements BlockEntityRenderer { - - public RenderLightCamo(BlockEntityRendererProvider.Context d) {} - - @Override - public boolean shouldRenderOffScreen(TileLightCamo te) { - return true; - } - - @Override - public void render(TileLightCamo te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - IItemHandler inv = te.getCapability(ForgeCapabilities.ITEM_HANDLER).orElse(null); - if (inv == null) { - return; - } - ItemStack stack = inv.getStackInSlot(0); - if (!stack.isEmpty()) { - RenderUtils.renderAsBlock(te.getBlockPos(), te.getShape(), matrixStack, stack, 1F, 1F); - } - } -} diff --git a/src/main/java/com/lothrazar/cyclic/block/lightcompr/TileLightCamo.java b/src/main/java/com/lothrazar/cyclic/block/lightcompr/TileLightCamo.java deleted file mode 100644 index b36a7dda9..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/lightcompr/TileLightCamo.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.lothrazar.cyclic.block.lightcompr; - -import java.util.ArrayList; -import java.util.List; -import com.lothrazar.cyclic.block.TileBlockEntityCyclic; -import com.lothrazar.cyclic.registry.TileRegistry; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemStackHandler; - -public class TileLightCamo extends TileBlockEntityCyclic { - - ItemStackHandler notInventory = new ItemStackHandler(1); - private LazyOptional inventoryCap = LazyOptional.of(() -> notInventory); - - public TileLightCamo(BlockPos pos, BlockState state) { - super(TileRegistry.LIGHT_CAMO.get(), pos, state); - } - - @Override - public void load(CompoundTag tag) { - super.load(tag); - notInventory.deserializeNBT(tag.getCompound(NBTINV)); - } - - @Override - public void saveAdditional(CompoundTag tag) { - tag.put(NBTINV, notInventory.serializeNBT()); - super.saveAdditional(tag); - } - - @Override - public AABB getRenderBoundingBox() { - return BlockEntity.INFINITE_EXTENT_AABB; - } - - @Override - public void invalidateCaps() { - inventoryCap.invalidate(); - super.invalidateCaps(); - } - - @Override - public LazyOptional getCapability(Capability cap, Direction side) { - if (cap == ForgeCapabilities.ITEM_HANDLER) { - return inventoryCap.cast(); - } - return super.getCapability(cap, side); - } - - @Override - public void setField(int field, int value) {} - - @Override - public int getField(int field) { - return 0; - } - - public List getShape() { - List lis = new ArrayList(); - lis.add(worldPosition); - return lis; - } -} diff --git a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffRender.java b/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffRender.java deleted file mode 100644 index 1e0964355..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffRender.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.lothrazar.cyclic.block.soundmuff.ghost; - -import com.lothrazar.cyclic.render.RenderUtils; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; - -public class SoundmuffRender implements BlockEntityRenderer { - - public SoundmuffRender(BlockEntityRendererProvider.Context d) {} - - @Override - public boolean shouldRenderOffScreen(SoundmuffTile te) { - return true; - } - - @Override - public void render(SoundmuffTile te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - IItemHandler inv = te.getCapability(ForgeCapabilities.ITEM_HANDLER).orElse(null); - if (inv == null) { - return; - } - ItemStack stack = inv.getStackInSlot(0); - if (!stack.isEmpty()) { - RenderUtils.renderAsBlock(te.getBlockPos(), te.getShape(), matrixStack, stack, 1F, 1F); - } - } -} diff --git a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffTile.java b/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffTile.java deleted file mode 100644 index 2d69eb86d..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmuffTile.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.lothrazar.cyclic.block.soundmuff.ghost; - -import java.util.ArrayList; -import java.util.List; -import com.lothrazar.cyclic.block.TileBlockEntityCyclic; -import com.lothrazar.cyclic.registry.TileRegistry; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemStackHandler; - -public class SoundmuffTile extends TileBlockEntityCyclic { - - ItemStackHandler notInventory = new ItemStackHandler(1); - private LazyOptional inventoryCap = LazyOptional.of(() -> notInventory); - - public SoundmuffTile(BlockPos pos, BlockState state) { - super(TileRegistry.SOUNDPROOFING_GHOST.get(), pos, state); - } - - @Override - public void load(CompoundTag tag) { - notInventory.deserializeNBT(tag.getCompound(NBTINV)); - super.load(tag); - } - - @Override - public void saveAdditional(CompoundTag tag) { - tag.put(NBTINV, notInventory.serializeNBT()); - super.saveAdditional(tag); - } - - @Override - public void invalidateCaps() { - inventoryCap.invalidate(); - super.invalidateCaps(); - } - - @Override - public LazyOptional getCapability(Capability cap, Direction side) { - if (cap == ForgeCapabilities.ITEM_HANDLER) { - return inventoryCap.cast(); - } - return super.getCapability(cap, side); - } - - @Override - public AABB getRenderBoundingBox() { - return BlockEntity.INFINITE_EXTENT_AABB; - } - - @Override - public void setField(int field, int value) {} - - @Override - public int getField(int field) { - return 0; - } - - public List getShape() { - List lis = new ArrayList(); - lis.add(worldPosition); - return lis; - } -} diff --git a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmufflerBlockGhost.java b/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmufflerBlockGhost.java deleted file mode 100644 index f56491518..000000000 --- a/src/main/java/com/lothrazar/cyclic/block/soundmuff/ghost/SoundmufflerBlockGhost.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.lothrazar.cyclic.block.soundmuff.ghost; - -import com.lothrazar.cyclic.block.soundmuff.SoundmufflerBlock; -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; - -public class SoundmufflerBlockGhost extends SoundmufflerBlock { - - public SoundmufflerBlockGhost(Properties properties) { - super(properties.noOcclusion()); - } - - @Override - public void registerClient() {} - - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return new SoundmuffTile(pos, state); - } - - // @Override - // public BlockEntityTicker getTicker(Level world, BlockState state, BlockEntityType type) { - // return createTickerHelper(type,TileRegistry.soundproofing_ghost, world.isClientSide ? SoundmuffTile::clientTick : SoundmuffTile::serverTick); - // } - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { - ItemStack stack = player.getItemInHand(handIn); - SoundmuffTile ent = (SoundmuffTile) world.getBlockEntity(pos); - if (stack.isEmpty() && handIn == InteractionHand.MAIN_HAND) { - //try to pull - ItemStack extracted = ent.notInventory.extractItem(0, 64, false); - if (!extracted.isEmpty()) { - //drop it - player.drop(extracted, true); - } - } - if (Block.byItem(stack.getItem()) == null) { - return super.use(state, world, pos, player, handIn, hit); - } - //replace it - if (!ent.notInventory.getStackInSlot(0).isEmpty()) { - //noempty so drop it first - ItemStack pulled = ent.notInventory.extractItem(0, 64, false); - player.drop(pulled, true); - } - //is it empty so now just replace every time - ItemStack copy = new ItemStack(stack.getItem(), 1); - ItemStack insertRemainder = ent.notInventory.insertItem(0, copy, false); - //success means no remainder, it took 1 - if (insertRemainder.isEmpty()) { - stack.shrink(1); //eat it!!! - return InteractionResult.SUCCESS; - } - //else do we nuke it? - // - return super.use(state, world, pos, player, handIn, hit); - } -} 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 45cba5837..d622cf521 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java +++ b/src/main/java/com/lothrazar/cyclic/block/tank/BlockFluidTank.java @@ -13,7 +13,6 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockGetter; @@ -51,7 +50,7 @@ public boolean hasAnalogOutputSignal(BlockState bs) { @Override public int getAnalogOutputSignal(BlockState st, Level level, BlockPos pos) { - return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); + return calcRedstoneFromFluid(level.getBlockEntity(pos)); } @Override 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 ad37e31da..9401d4db9 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java +++ b/src/main/java/com/lothrazar/cyclic/block/tank/TileTank.java @@ -80,10 +80,12 @@ public void setFluid(FluidStack fluid) { // @Override public void tick() { - //drain below but only to one of myself + //drain below but only to one of myself BlockEntity below = this.level.getBlockEntity(this.worldPosition.below()); if (below != null && below instanceof TileTank) { FluidHelpers.tryFillPositionFromTank(level, this.worldPosition.below(), Direction.UP, tank, TRANSFER_FLUID_PER_TICK); + this.updateComparatorOutputLevel(); + this.updateComparatorOutputLevelAt(worldPosition.below()); } } } 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 608d2de24..7e72995e6 100644 --- a/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java +++ b/src/main/java/com/lothrazar/cyclic/block/tankcask/BlockCask.java @@ -9,7 +9,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -34,7 +33,7 @@ public boolean hasAnalogOutputSignal(BlockState bs) { @Override public int getAnalogOutputSignal(BlockState st, Level level, BlockPos pos) { - return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); + return calcRedstoneFromFluid(level.getBlockEntity(pos)); } @Override diff --git a/src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java b/src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java index f592c0896..31b3cc2ba 100644 --- a/src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java +++ b/src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java @@ -94,11 +94,15 @@ import com.lothrazar.cyclic.registry.CommandRegistry.CyclicCommands; import com.lothrazar.cyclic.registry.MaterialRegistry; import com.lothrazar.cyclic.registry.PotionRegistry; +import com.lothrazar.cyclic.util.StringParseUtil; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; import net.minecraftforge.common.ForgeConfigSpec.IntValue; import net.minecraftforge.fml.loading.FMLPaths; +import net.minecraftforge.registries.ForgeRegistries; public class ConfigRegistry { @@ -402,6 +406,27 @@ private static void initConfig() { CFG.pop(); //heart CFG.pop(); //items CFG.comment(WALL, " Block specific configs", WALL).push("blocks"); //////////////////////////////////////////////////////////////////////////////////// blocks + CFG.push("facades"); + CABLE_FACADES = CFG.comment("\r\n Allow cables to have blocks placed in them as facades (sneak-left-click to set; use empty hand to remove). Set to false to disable facades") + .define("cables.enabled", true); + //a few default + List list = Arrays.asList("minecraft:ladder", "minecraft:double_plant", "minecraft:waterlily", + "minecraft:torch", "minecraft:*_torch", "minecraft:redstone", "minecraft:iron_bars", + "minecraft:chest", "minecraft:ender_chest", "minecraft:sculk_vein", "minecraft:string", "minecraft:vine", + "minecraft:rail", + "minecraft:*_rail", + "minecraft:brewing_stand", + "minecraft:*_dripleaf", + "minecraft:*_pane", + "minecraft:*_sapling", "minecraft:*_sign", + "minecraft:*_door", + "minecraft:*_banner", "minecraft:*_shulker_box", + "cyclic:*_pipe", "cyclic:*_bars", + "storagenetwork:*"); + FACADE_IGNORELIST = CFG.comment("\r\n These blocks are not allowed to be used as Facades for blocks because they look weird (used by cables and Glowstone Facade and Soundproofing Facade and others)") + .define("itemsNotAllowed", list); + CFG.pop(); + // TRANSFER_NODES_DIMENSIONAL = CFG.comment(" Allows the dimensional Transfer Nodes to cross dimensions " + "(no chunk loading is done, you have to do that on your own); " + "This affects blocks cyclic:wireless_energy, cyclic:wireless_item, cyclic:wireless_fluid, cyclic:wireless_transmitter; " @@ -629,4 +654,15 @@ public static Map getMappedBeheading() { } return mappedBeheading; } + + public static BooleanValue CABLE_FACADES; + private static ConfigValue> FACADE_IGNORELIST; + + public static boolean isFacadeAllowed(ItemStack item) { + ResourceLocation itemId = ForgeRegistries.ITEMS.getKey(item.getItem()); + if (StringParseUtil.isInList(FACADE_IGNORELIST.get(), itemId)) { + return false; + } + return true; + } } diff --git a/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java b/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java index 595ddb78b..9306bc79f 100644 --- a/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java +++ b/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java @@ -1,7 +1,9 @@ package com.lothrazar.cyclic.event; +import com.lothrazar.cyclic.ModCyclic; import com.lothrazar.cyclic.api.IEntityInteractable; import com.lothrazar.cyclic.block.cable.CableBase; +import com.lothrazar.cyclic.block.facade.IBlockFacade; import com.lothrazar.cyclic.block.scaffolding.ItemScaffolding; import com.lothrazar.cyclic.config.ConfigRegistry; import com.lothrazar.cyclic.data.DataTags; @@ -19,9 +21,11 @@ import com.lothrazar.cyclic.item.equipment.ShieldCyclicItem; import com.lothrazar.cyclic.item.food.LoftyStatureApple; import com.lothrazar.cyclic.item.storagebag.ItemStorageBag; +import com.lothrazar.cyclic.net.BlockFacadeMessage; import com.lothrazar.cyclic.registry.BlockRegistry; import com.lothrazar.cyclic.registry.EnchantRegistry; import com.lothrazar.cyclic.registry.ItemRegistry; +import com.lothrazar.cyclic.registry.PacketRegistry; import com.lothrazar.cyclic.registry.PotionEffectRegistry; import com.lothrazar.cyclic.registry.SoundRegistry; import com.lothrazar.cyclic.util.AttributesUtil; @@ -33,6 +37,8 @@ import com.lothrazar.cyclic.util.SoundUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; @@ -50,13 +56,18 @@ import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult.Type; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.ForgeMod; import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.living.LivingDamageEvent; @@ -472,16 +483,19 @@ public void onEntityInteractEvent(EntityInteract event) { public void onHit(PlayerInteractEvent.LeftClickBlock event) { Player player = event.getEntity(); ItemStack held = player.getItemInHand(event.getHand()); - if (held.isEmpty()) { - return; - } - Level world = player.getCommandSenderWorld(); + var world = player.getCommandSenderWorld(); + BlockState target = world.getBlockState(event.getPos()); ///////////// shape if (held.getItem() instanceof ShapeCard && player.isCrouching()) { - BlockState target = world.getBlockState(event.getPos()); ShapeCard.setBlockState(held, target); ChatUtil.sendStatusMessage(player, target.getBlock().getDescriptionId()); } + if (player.isCrouching() + && target.getBlock() instanceof IBlockFacade) { + // + onHitFacadeHandler(event, player, held, target); + // + } ///////////////// builders if (held.getItem() instanceof BuilderItem) { if (BuilderActionType.getTimeout(held) > 0) { @@ -492,7 +506,7 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) { event.setCanceled(true); if (player.isCrouching()) { //pick out target block - BlockState target = world.getBlockState(event.getPos()); + // BlockState target = world.getBlockState(event.getPos()); BuilderActionType.setBlockState(held, target); ChatUtil.sendStatusMessage(player, target.getBlock().getDescriptionId()); event.setCanceled(true); @@ -513,6 +527,46 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) { } } + private void onHitFacadeHandler(PlayerInteractEvent.LeftClickBlock event, Player player, ItemStack held, BlockState target) { + if (held.isEmpty() && event.getLevel().isClientSide()) { + PacketRegistry.INSTANCE.sendToServer(new BlockFacadeMessage(event.getPos(), true)); + } + else { + Block block = Block.byItem(held.getItem()); // getBlockFromItem + if (block == null || block == Blocks.AIR || block == target.getBlock()) { + return; + } + if (target.getBlock() instanceof CableBase) { + if (!ConfigRegistry.CABLE_FACADES.get()) { + return; + } + } + if (!ConfigRegistry.isFacadeAllowed(held)) { + ModCyclic.LOGGER.info("not allowed to use this item as a facade from config: " + held.getItem()); + return; + } + if (event.getLevel().isClientSide()) { + onHitFacadeClient(event, player, held, block); + } + } + //cancel the event so creative players will not break it + event.setCanceled(true); + } + + @OnlyIn(Dist.CLIENT) + private void onHitFacadeClient(PlayerInteractEvent.LeftClickBlock event, Player player, ItemStack held, Block block) { + //pick the block, write to tags, and send to server + boolean pickFluids = false; + double reach = player.getReachDistance(); + HitResult bhr = player.pick(reach, 1, pickFluids); // BlockHitResult + if (bhr.getType() == HitResult.Type.BLOCK) { + BlockPlaceContext context = new BlockPlaceContext(player, event.getHand(), held, (BlockHitResult) bhr); // BlockItemUseContext + BlockState facadeState = block.getStateForPlacement(context); + CompoundTag tags = (facadeState == null) ? null : NbtUtils.writeBlockState(facadeState); + PacketRegistry.INSTANCE.sendToServer(new BlockFacadeMessage(event.getPos(), tags)); + } + } + @SubscribeEvent public void onPlayerPickup(EntityItemPickupEvent event) { if (event.getEntity() instanceof Player) { diff --git a/src/main/java/com/lothrazar/cyclic/net/BlockFacadeMessage.java b/src/main/java/com/lothrazar/cyclic/net/BlockFacadeMessage.java new file mode 100644 index 000000000..523d9538f --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/net/BlockFacadeMessage.java @@ -0,0 +1,66 @@ +package com.lothrazar.cyclic.net; + +import java.util.function.Supplier; +import com.lothrazar.cyclic.block.facade.IBlockFacade; +import com.lothrazar.cyclic.block.facade.ITileFacade; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.network.NetworkEvent; + +public class BlockFacadeMessage { + + private BlockPos pos; + private boolean erase = false; + private CompoundTag blockStateTag = new CompoundTag(); + + private BlockFacadeMessage() {} + + public BlockFacadeMessage(BlockPos pos, CompoundTag state) { + this.pos = pos; + this.blockStateTag = state; + this.erase = false; + } + + public BlockFacadeMessage(BlockPos pos, boolean eraseIn) { + this.pos = pos; + this.erase = eraseIn; + blockStateTag = new CompoundTag(); + } + + public static void handle(BlockFacadeMessage message, Supplier ctx) { + ctx.get().enqueueWork(() -> { + ServerPlayer player = ctx.get().getSender(); + var serverWorld = player.getCommandSenderWorld(); + BlockState bs = serverWorld.getBlockState(message.pos); + if (bs.getBlock() instanceof IBlockFacade facadeBlock) { + ITileFacade tile = facadeBlock.getTileFacade(serverWorld, message.pos); + if (message.erase) { + tile.setFacade(null); + } + else { + tile.setFacade(message.blockStateTag); + } + serverWorld.markAndNotifyBlock(message.pos, serverWorld.getChunkAt(message.pos), + bs, bs, 3, 1); + } + }); + ctx.get().setPacketHandled(true); + } + + public static BlockFacadeMessage decode(FriendlyByteBuf buf) { + BlockFacadeMessage message = new BlockFacadeMessage(); + message.erase = buf.readBoolean(); + message.pos = buf.readBlockPos(); + message.blockStateTag = buf.readNbt(); + return message; + } + + public static void encode(BlockFacadeMessage msg, FriendlyByteBuf buf) { + buf.writeBoolean(msg.erase); + buf.writeBlockPos(msg.pos); + buf.writeNbt(msg.blockStateTag); + } +} diff --git a/src/main/java/com/lothrazar/cyclic/registry/BlockRegistry.java b/src/main/java/com/lothrazar/cyclic/registry/BlockRegistry.java index 7f7822ac6..63d912822 100644 --- a/src/main/java/com/lothrazar/cyclic/registry/BlockRegistry.java +++ b/src/main/java/com/lothrazar/cyclic/registry/BlockRegistry.java @@ -56,6 +56,8 @@ import com.lothrazar.cyclic.block.expcollect.BlockExpPylon; import com.lothrazar.cyclic.block.eye.BlockEye; import com.lothrazar.cyclic.block.eyetp.BlockEyeTp; +import com.lothrazar.cyclic.block.facade.light.BlockLightFacade; +import com.lothrazar.cyclic.block.facade.soundmuff.SoundmufflerBlockFacade; import com.lothrazar.cyclic.block.fan.BlockFan; import com.lothrazar.cyclic.block.fanslab.BlockFanSlab; import com.lothrazar.cyclic.block.fishing.BlockFisher; @@ -74,7 +76,6 @@ import com.lothrazar.cyclic.block.hopperfluid.BlockFluidHopper; import com.lothrazar.cyclic.block.hoppergold.BlockGoldHopper; import com.lothrazar.cyclic.block.laser.BlockLaser; -import com.lothrazar.cyclic.block.lightcompr.BlockLightCamo; import com.lothrazar.cyclic.block.magnet.BlockMagnetPanel; import com.lothrazar.cyclic.block.melter.BlockMelter; import com.lothrazar.cyclic.block.miner.BlockMiner; @@ -98,7 +99,6 @@ import com.lothrazar.cyclic.block.shears.BlockShearing; import com.lothrazar.cyclic.block.solidifier.BlockSolidifier; import com.lothrazar.cyclic.block.soundmuff.SoundmufflerBlock; -import com.lothrazar.cyclic.block.soundmuff.ghost.SoundmufflerBlockGhost; import com.lothrazar.cyclic.block.soundplay.BlockSoundPlayer; import com.lothrazar.cyclic.block.soundrecord.BlockSoundRecorder; import com.lothrazar.cyclic.block.spawntriggers.BlockAltarNoTraders; @@ -184,7 +184,7 @@ public void appendHoverText(ItemStack stack, BlockGetter worldIn, List GENERATOR_ITEM = BLOCKS.register("generator_item", () -> new BlockGeneratorDrops(Block.Properties.of(Material.METAL))); public static final RegistryObject PACKAGER = BLOCKS.register("packager", () -> new BlockPackager(Block.Properties.of(Material.METAL))); public static final RegistryObject TERRA_PRETA = BLOCKS.register("terra_preta", () -> new BlockTerraPreta(Block.Properties.of(Material.DIRT).sound(SoundType.GRAVEL))); - public static final RegistryObject LIGHT_CAMO = BLOCKS.register("light_camo", () -> new BlockLightCamo(Block.Properties.of(Material.METAL))); + public static final RegistryObject LIGHT_CAMO = BLOCKS.register("light_camo", () -> new BlockLightFacade(Block.Properties.of(Material.METAL))); public static final RegistryObject LASER = BLOCKS.register("laser", () -> new BlockLaser(Block.Properties.of(Material.METAL))); public static final RegistryObject FLOWER_CYAN = BLOCKS.register("flower_cyan", () -> new FlowerSimpleBlock(Block.Properties.of(Material.PLANT, DyeColor.CYAN))); public static final RegistryObject FLOWER_PURPLE_TULIP = BLOCKS.register("flower_purple_tulip", () -> new FlowerSimpleBlock(Block.Properties.of(Material.PLANT, DyeColor.PURPLE))); @@ -265,7 +265,7 @@ protected int getSignalForState(BlockState st) { public static final RegistryObject BEACON = BLOCKS.register("beacon", () -> new BlockPotion(Block.Properties.of(Material.METAL))); public static final RegistryObject BEACON_REDSTONE = BLOCKS.register("beacon_redstone", () -> new BlockBeaconRedstone(Block.Properties.of(Material.STONE).lightLevel(p -> 4))); public static final RegistryObject ANTI_BEACON = BLOCKS.register("anti_beacon", () -> new BlockAntiBeacon(Block.Properties.of(Material.STONE).lightLevel(p -> 2))); - public static final RegistryObject SOUNDPROOFING_GHOST = BLOCKS.register("soundproofing_ghost", () -> new SoundmufflerBlockGhost(Block.Properties.of(Material.STONE))); + public static final RegistryObject SOUNDPROOFING_GHOST = BLOCKS.register("soundproofing_ghost", () -> new SoundmufflerBlockFacade(Block.Properties.of(Material.STONE))); public static final RegistryObject SOUNDPROOFING = BLOCKS.register("soundproofing", () -> new SoundmufflerBlock(Block.Properties.of(Material.STONE))); public static final RegistryObject CLOCK = BLOCKS.register("clock", () -> new BlockRedstoneClock(Block.Properties.of(Material.STONE))); public static final RegistryObject WIRELESS_RECEIVER = BLOCKS.register("wireless_receiver", () -> new BlockWirelessRec(Block.Properties.of(Material.STONE))); diff --git a/src/main/java/com/lothrazar/cyclic/registry/ClientRegistryCyclic.java b/src/main/java/com/lothrazar/cyclic/registry/ClientRegistryCyclic.java index d34f9fc84..b5c8e860e 100644 --- a/src/main/java/com/lothrazar/cyclic/registry/ClientRegistryCyclic.java +++ b/src/main/java/com/lothrazar/cyclic/registry/ClientRegistryCyclic.java @@ -14,12 +14,14 @@ import com.lothrazar.cyclic.block.dropper.RenderDropper; import com.lothrazar.cyclic.block.enderitemshelf.ItemShelfRenderer; import com.lothrazar.cyclic.block.endershelf.EnderShelfRenderer; +import com.lothrazar.cyclic.block.facade.RenderCableFacade; +import com.lothrazar.cyclic.block.facade.light.RenderLightFacade; +import com.lothrazar.cyclic.block.facade.soundmuff.SoundmuffRender; import com.lothrazar.cyclic.block.fan.RenderFan; import com.lothrazar.cyclic.block.fishing.RenderFisher; import com.lothrazar.cyclic.block.forester.RenderForester; import com.lothrazar.cyclic.block.harvester.RenderHarvester; import com.lothrazar.cyclic.block.laser.RenderLaser; -import com.lothrazar.cyclic.block.lightcompr.RenderLightCamo; import com.lothrazar.cyclic.block.melter.RenderMelter; import com.lothrazar.cyclic.block.miner.RenderMiner; import com.lothrazar.cyclic.block.peatfarm.RenderPeatFarm; @@ -27,7 +29,6 @@ import com.lothrazar.cyclic.block.shapebuilder.RenderStructure; import com.lothrazar.cyclic.block.shapedata.RenderShapedata; import com.lothrazar.cyclic.block.solidifier.RenderSolidifier; -import com.lothrazar.cyclic.block.soundmuff.ghost.SoundmuffRender; import com.lothrazar.cyclic.block.sprinkler.RenderSprinkler; import com.lothrazar.cyclic.block.tank.RenderTank; import com.lothrazar.cyclic.block.wireless.redstone.RenderTransmit; @@ -148,7 +149,7 @@ public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers ev event.registerBlockEntityRenderer(TileRegistry.FORESTER.get(), RenderForester::new); event.registerBlockEntityRenderer(TileRegistry.HARVESTER.get(), RenderHarvester::new); event.registerBlockEntityRenderer(TileRegistry.LASER.get(), RenderLaser::new); - event.registerBlockEntityRenderer(TileRegistry.LIGHT_CAMO.get(), RenderLightCamo::new); + event.registerBlockEntityRenderer(TileRegistry.LIGHT_CAMO.get(), RenderLightFacade::new); event.registerBlockEntityRenderer(TileRegistry.MELTER.get(), RenderMelter::new); event.registerBlockEntityRenderer(TileRegistry.MINER.get(), RenderMiner::new); event.registerBlockEntityRenderer(TileRegistry.SCREEN.get(), RenderScreentext::new); @@ -161,6 +162,10 @@ public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers ev event.registerBlockEntityRenderer(TileRegistry.BEACON.get(), RenderBeaconPotion::new); event.registerBlockEntityRenderer(TileRegistry.ANTI_BEACON.get(), RenderBeaconAnti::new); event.registerBlockEntityRenderer(TileRegistry.BEACON_REDSTONE.get(), RenderBeaconRedstone::new); + //cable renderers + event.registerBlockEntityRenderer(TileRegistry.ENERGY_PIPE.get(), RenderCableFacade::new); + event.registerBlockEntityRenderer(TileRegistry.ITEM_PIPE.get(), RenderCableFacade::new); + event.registerBlockEntityRenderer(TileRegistry.FLUID_PIPE.get(), RenderCableFacade::new); } @SuppressWarnings("deprecation") //shield itemproperty diff --git a/src/main/java/com/lothrazar/cyclic/registry/PacketRegistry.java b/src/main/java/com/lothrazar/cyclic/registry/PacketRegistry.java index 6f5909a0e..8d1fa3bf5 100644 --- a/src/main/java/com/lothrazar/cyclic/registry/PacketRegistry.java +++ b/src/main/java/com/lothrazar/cyclic/registry/PacketRegistry.java @@ -5,6 +5,7 @@ import com.lothrazar.cyclic.item.random.PacketRandomize; import com.lothrazar.cyclic.item.scythe.PacketScythe; import com.lothrazar.cyclic.item.transporter.PacketChestSack; +import com.lothrazar.cyclic.net.BlockFacadeMessage; import com.lothrazar.cyclic.net.PacketBaseCyclic; import com.lothrazar.cyclic.net.PacketCraftAction; import com.lothrazar.cyclic.net.PacketEnergySync; @@ -69,6 +70,7 @@ public static void setup() { INSTANCE.registerMessage(id++, PacketEntityLaser.class, PacketEntityLaser::encode, PacketEntityLaser::decode, PacketEntityLaser::handle); INSTANCE.registerMessage(id++, PacketPlayerSyncToClient.class, PacketPlayerSyncToClient::encode, PacketPlayerSyncToClient::decode, PacketPlayerSyncToClient::handle); INSTANCE.registerMessage(id++, PacketSyncManaToClient.class, PacketSyncManaToClient::encode, PacketSyncManaToClient::decode, PacketSyncManaToClient::handle); + INSTANCE.registerMessage(id++, BlockFacadeMessage.class, BlockFacadeMessage::encode, BlockFacadeMessage::decode, BlockFacadeMessage::handle); } public static void sendToAllClients(Level world, PacketBaseCyclic packet) { diff --git a/src/main/java/com/lothrazar/cyclic/registry/TileRegistry.java b/src/main/java/com/lothrazar/cyclic/registry/TileRegistry.java index ef382048b..784f757be 100644 --- a/src/main/java/com/lothrazar/cyclic/registry/TileRegistry.java +++ b/src/main/java/com/lothrazar/cyclic/registry/TileRegistry.java @@ -37,6 +37,8 @@ import com.lothrazar.cyclic.block.expcollect.TileExpPylon; import com.lothrazar.cyclic.block.eye.TileEye; import com.lothrazar.cyclic.block.eyetp.TileEyeTp; +import com.lothrazar.cyclic.block.facade.light.TileLightFacade; +import com.lothrazar.cyclic.block.facade.soundmuff.SoundmuffTileFacade; import com.lothrazar.cyclic.block.fan.TileFan; import com.lothrazar.cyclic.block.fanslab.TileFanSlab; import com.lothrazar.cyclic.block.fishing.TileFisher; @@ -51,7 +53,6 @@ import com.lothrazar.cyclic.block.hopperfluid.TileFluidHopper; import com.lothrazar.cyclic.block.hoppergold.TileGoldHopper; import com.lothrazar.cyclic.block.laser.TileLaser; -import com.lothrazar.cyclic.block.lightcompr.TileLightCamo; import com.lothrazar.cyclic.block.magnet.TileInsertingMagnet; import com.lothrazar.cyclic.block.melter.TileMelter; import com.lothrazar.cyclic.block.miner.TileMiner; @@ -66,7 +67,6 @@ import com.lothrazar.cyclic.block.shapebuilder.TileStructure; import com.lothrazar.cyclic.block.shapedata.TileShapedata; import com.lothrazar.cyclic.block.solidifier.TileSolidifier; -import com.lothrazar.cyclic.block.soundmuff.ghost.SoundmuffTile; import com.lothrazar.cyclic.block.soundplay.TileSoundPlayer; import com.lothrazar.cyclic.block.soundrecord.TileSoundRecorder; import com.lothrazar.cyclic.block.spawntriggers.TileAltar; @@ -123,8 +123,8 @@ public class TileRegistry { public static final RegistryObject> CRUSHER = TILES.register("crusher", () -> BlockEntityType.Builder.of(TileCrusher::new, BlockRegistry.CRUSHER.get()).build(null)); public static final RegistryObject> TELEPORT = TILES.register("teleport", () -> BlockEntityType.Builder.of(TileTeleport::new, BlockRegistry.TELEPORT.get()).build(null)); public static final RegistryObject> SPIKES_DIAMOND = TILES.register("spikes_diamond", () -> BlockEntityType.Builder.of(TileDiamondSpikes::new, BlockRegistry.SPIKES_DIAMOND.get()).build(null)); - public static final RegistryObject> LIGHT_CAMO = TILES.register("light_camo", () -> BlockEntityType.Builder.of(TileLightCamo::new, BlockRegistry.LIGHT_CAMO.get()).build(null)); - public static final RegistryObject> SOUNDPROOFING_GHOST = TILES.register("soundproofing_ghost", () -> BlockEntityType.Builder.of(SoundmuffTile::new, BlockRegistry.SOUNDPROOFING_GHOST.get()).build(null)); + public static final RegistryObject> LIGHT_CAMO = TILES.register("light_camo", () -> BlockEntityType.Builder.of(TileLightFacade::new, BlockRegistry.LIGHT_CAMO.get()).build(null)); + public static final RegistryObject> SOUNDPROOFING_GHOST = TILES.register("soundproofing_ghost", () -> BlockEntityType.Builder.of(SoundmuffTileFacade::new, BlockRegistry.SOUNDPROOFING_GHOST.get()).build(null)); public static final RegistryObject> TERRA_PRETA = TILES.register("terra_preta", () -> BlockEntityType.Builder.of(TileTerraPreta::new, BlockRegistry.TERRA_PRETA.get()).build(null)); public static final RegistryObject> EYE_REDSTONE = TILES.register("eye_redstone", () -> BlockEntityType.Builder.of(TileEye::new, BlockRegistry.EYE_REDSTONE.get()).build(null)); public static final RegistryObject> EYE_TELEPORT = TILES.register("eye_teleport", () -> BlockEntityType.Builder.of(TileEyeTp::new, BlockRegistry.EYE_TELEPORT.get()).build(null)); diff --git a/src/main/java/com/lothrazar/cyclic/util/FacadeUtil.java b/src/main/java/com/lothrazar/cyclic/util/FacadeUtil.java new file mode 100644 index 000000000..c89fef614 --- /dev/null +++ b/src/main/java/com/lothrazar/cyclic/util/FacadeUtil.java @@ -0,0 +1,26 @@ +package com.lothrazar.cyclic.util; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.blaze3d.vertex.VertexMultiConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.data.ModelData; + +public class FacadeUtil { + + public static void renderBlockState(Level level, BlockPos pos, BlockRenderDispatcher brd, ModelBlockRenderer renderer, + MultiBufferSource ibuffer, PoseStack matrixStack, BlockState facadeState, int packedLight, int packedOverlay) { + BakedModel model = brd.getBlockModel(facadeState); + VertexConsumer vertexConsumer = VertexMultiConsumer.create(ibuffer.getBuffer(RenderType.solid())); + renderer.tesselateBlock(level, model, facadeState, pos, + matrixStack, vertexConsumer, false, level.random, packedLight, packedOverlay, + ModelData.EMPTY, RenderType.solid()); + } +} diff --git a/src/main/resources/assets/cyclic/lang/en_us.json b/src/main/resources/assets/cyclic/lang/en_us.json index b6a29cc44..19865fec1 100644 --- a/src/main/resources/assets/cyclic/lang/en_us.json +++ b/src/main/resources/assets/cyclic/lang/en_us.json @@ -325,10 +325,10 @@ "block.cyclic.dark_glass_connected": "Dark Connected Glass", "block.cyclic.dark_glass_connected.tooltip": "Immune to light, explosions, and wither blasts", "block.cyclic.dark_glass_connected.guide": "Self-connecting textures. Unlike regular glass, does not let light pass through.Oh, and it's also immune explosions, including those caused by the Wither.", - "block.cyclic.light_camo": "Concentrated Glowstone", + "block.cyclic.light_camo": "Glowstone Facade", "block.cyclic.light_camo.tooltip": "Use block on it to copy appearance", "block.cyclic.light_camo.guide": "Produces light, and copies a block appearance. Contains a block projection", - "block.cyclic.soundproofing_ghost": "Concentrated Soundproofing", + "block.cyclic.soundproofing_ghost": "Soundproofing Facade", "block.cyclic.soundproofing_ghost.guide": "Prevents sound, and copies a block appearance. Use block on it to copy appearance", "block.cyclic.soundproofing_ghost.tooltip": "Use block on it to copy appearance", "block.cyclic.soundproofing": "Soundproofing", @@ -1439,6 +1439,7 @@ "item.minecraft.lingering_potion.effect.cyclic_reach_distance": "Lingering Potion of Reach Distance", "item.minecraft.tipped_arrow.effect.cyclic_reach_distance": "Arrow of Reach Distance", + "effect.cyclic.haste": "Haste", "item.minecraft.potion.effect.cyclic_haste": "Potion of Haste", "item.minecraft.splash_potion.effect.cyclic_haste": "Splash Potion of Haste", @@ -1452,7 +1453,6 @@ "item.minecraft.potion.effect.cyclic_haste.guide": "The Potion of Haste apples the Haste effect to the target, increasing their mining speed.", "item.minecraft.potion.effect.cyclic_swimspeed.guide": "The Potion of Swim Speed greatly increases its target's speed while moving through liquids.", - "effect.cyclic.stun": "Paralyze", "effect.cyclic.stun.description": "Stun the entity so it cannot move for a time", "item.minecraft.potion.effect.cyclic_stun": "Potion of Paralyze", diff --git a/update.json b/update.json index c0c060311..50eb77827 100644 --- a/update.json +++ b/update.json @@ -89,7 +89,6 @@ - }, "1.18.2": { "1.6.0": "Ported Cyclic[1.16.5]-1.5.8 to Minecraft [1.17.1] & forge-37.0.85+. Altered a few crafting recipes to use new items. Removed Peat Generator (Use Peat items in Material Generator). Removed 5 Mason blocks, replaced with Compressed Cobblestone, Flint Block. Added Peace Candle, Translocation Platform, Stone Mattock, Crushing Macerator, and Lava Sponge. Added Copper Tools and Amethyst Tools, Copper Lantern, Copper Chain, Copper Bars, Gold Chain, Gold Bars, Gold Lantern (Art by @shynieke). Added Copper Nuggets and Netherite Nuggets. Added Netherite Lanterns, chains, and bars. Added 3 Pressure Plates: Copper Netherite and Obsidian. ", @@ -152,7 +151,8 @@ ,"1.8.5":"Backport Mud block solidifier recipe. 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. Add recipes in the solidifier machine for Waxed copper blocks " - ,"1.9.0":"Added an optional item slot in the Block Breaker using the BlockState Data Card so players have the option to limit the block breaker to only the targets listed in the data card. Add new block data tags cyclic:ignored/breaker and cyclic:ignored/miner so that pack devs can customize these machines to not break certain blocks (regardless of hardness). Many blocks now allow minecraft:comparator to pull a redstone signal based on inventory contents (most machines and blocks that have inventory). 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. Several blocks added to block-tag mineable/pickaxe (thanks to darkosto) " + ,"1.9.0":"Added an optional item slot in the Block Breaker using the BlockState Data Card so players have the option to limit the block breaker to only the targets listed in the data card. Add new block data tags cyclic:ignored/breaker and cyclic:ignored/miner so that pack devs can customize these machines to not break certain blocks (regardless of hardness). Many blocks now allow minecraft:comparator to pull a redstone signal based on inventory contents (most machines and blocks that have inventory). 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. Facades overhaul backported from 1.20.1: Renamed 'Concentrated Glowstone' to 'Glowstone Facade' and 'Concentrated Soundproofing' to 'Soundproofing Facade' . Backport cable facades from 1.20.1 (New feature with cables: hide them using solid blocks with a feature called 'facades', just sneak-left-click a block onto the cable; empty hand to remove it) " + } }