diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 7145b9f8c..185826177 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -80,12 +80,12 @@ f03fc3f6983755f0c8d231554a92acfcef9e90a0 assets/actuallyadditions/blockstates/la 04e242e27c9debdcf924adc4e7e85e8879c8d9ba assets/actuallyadditions/blockstates/lamp_red.json 7cfadd0f25de8b5035641238a8e18ffac1ef356c assets/actuallyadditions/blockstates/lamp_white.json 5e526bf21366f7382a19261b71c73f96d62a3a0c assets/actuallyadditions/blockstates/lamp_yellow.json -c384311568a9dc7a4313ebf050f590792de7e7aa assets/actuallyadditions/blockstates/laser_relay.json -64b9076d7ebd666dd8cabd88c8fdab6e5ae15124 assets/actuallyadditions/blockstates/laser_relay_advanced.json -3e11aee568ff4c28dc9a51a6800faa3047a0aa81 assets/actuallyadditions/blockstates/laser_relay_extreme.json -89e137a4932755e23cd7dc3e46d223b2332d11e1 assets/actuallyadditions/blockstates/laser_relay_fluids.json -a3821b684b590b815499ff25847ecfbbc217f14d assets/actuallyadditions/blockstates/laser_relay_item.json -33069098e2bb435c696b1862d9d47971b3247117 assets/actuallyadditions/blockstates/laser_relay_item_advanced.json +9a80b2d1281ed112a7e1a3b9639c5dc872ccf8b8 assets/actuallyadditions/blockstates/laser_relay.json +aa09a7e86d9bf3ad1bad45c9f9b9d5f0c13afcc9 assets/actuallyadditions/blockstates/laser_relay_advanced.json +95f8ec3018d85b3c99065a913a73217d5ea3a086 assets/actuallyadditions/blockstates/laser_relay_extreme.json +e18d4ba1f8eedefbdf0c6b86bc77511130ced533 assets/actuallyadditions/blockstates/laser_relay_fluids.json +a5bd1eb03cecd98679f49205efcc9276ec3092da assets/actuallyadditions/blockstates/laser_relay_item.json +fb19f1e3140a2481745c6bb844a75344b3aa642d assets/actuallyadditions/blockstates/laser_relay_item_advanced.json eae81ba22d5b7761dd5a03d909d857007a40c9e2 assets/actuallyadditions/blockstates/lava_factory_casing.json 9bcb5be7108d01028f654dcc8698b801a1663117 assets/actuallyadditions/blockstates/lava_factory_controller.json 27a1c7620994f8f4b325e9323003e9a8ea9ee931 assets/actuallyadditions/blockstates/leaf_generator.json diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay.json index 2ecdc7a86..dfa9bb4f7 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_advanced.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_advanced.json index bbf55a90a..2627dca6c 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_advanced.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_advanced.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay_advanced", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay_advanced" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay_advanced", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay_advanced", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay_advanced", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay_advanced", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_extreme.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_extreme.json index f8525e850..b3f28fa8f 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_extreme.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_extreme.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay_extreme", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay_extreme" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay_extreme", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay_extreme", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay_extreme", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay_extreme", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_fluids.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_fluids.json index d7f99a683..e48e06e5e 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_fluids.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_fluids.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay_fluids", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay_fluids" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay_fluids", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay_fluids", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay_fluids", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay_fluids", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item.json index 882b52686..3eaca76de 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay_item", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay_item" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay_item", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay_item", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay_item", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay_item", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item_advanced.json b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item_advanced.json index 410d30544..c85fe8761 100644 --- a/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item_advanced.json +++ b/src/generated/resources/assets/actuallyadditions/blockstates/laser_relay_item_advanced.json @@ -1,7 +1,30 @@ { "variants": { - "": { + "facing=down": { + "model": "actuallyadditions:block/laser_relay_item_advanced", + "x": 180 + }, + "facing=up": { "model": "actuallyadditions:block/laser_relay_item_advanced" + }, + "facing=north": { + "model": "actuallyadditions:block/laser_relay_item_advanced", + "x": 90 + }, + "facing=south": { + "model": "actuallyadditions:block/laser_relay_item_advanced", + "x": 90, + "y": 180 + }, + "facing=west": { + "model": "actuallyadditions:block/laser_relay_item_advanced", + "x": 90, + "y": 270 + }, + "facing=east": { + "model": "actuallyadditions:block/laser_relay_item_advanced", + "x": 90, + "y": 90 } } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java index af542fee5..b3e3ff6a5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java @@ -2,7 +2,6 @@ package de.ellpeck.actuallyadditions.data; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; -import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import net.minecraft.block.*; import net.minecraft.data.DataGenerator; import net.minecraft.state.properties.BlockStateProperties; @@ -72,12 +71,12 @@ public class BlockStateGenerator extends BlockStateProvider { buildCubeAll(ActuallyBlocks.EMPOWERED_VOID_CRYSTAL); buildCubeAll(ActuallyBlocks.EMPOWERED_EMERADIC_CRYSTAL); buildCubeAll(ActuallyBlocks.EMPOWERED_ENORI_CRYSTAL); - standardBlock(ActuallyBlocks.LASER_RELAY); - standardBlock(ActuallyBlocks.LASER_RELAY_ADVANCED); - standardBlock(ActuallyBlocks.LASER_RELAY_EXTREME); - standardBlock(ActuallyBlocks.LASER_RELAY_FLUIDS); - standardBlock(ActuallyBlocks.LASER_RELAY_ITEM); - standardBlock(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY_ADVANCED); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY_EXTREME); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY_FLUIDS); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY_ITEM); + fullyDirectionalBlock(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED); standardBlock(ActuallyBlocks.RANGED_COLLECTOR); standardBlock(ActuallyBlocks.XP_SOLIDIFIER); standardBlock(ActuallyBlocks.ENERGIZER); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index c7600d10a..c24cfcd68 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -26,12 +26,12 @@ import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.ItemCoffee; -import de.ellpeck.actuallyadditions.mod.items.lens.LensMining; import de.ellpeck.actuallyadditions.mod.misc.BannerHelper; import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.util.ResourceReloader; import net.minecraft.entity.EntityClassification; @@ -43,6 +43,7 @@ import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.event.AddReloadListenerEvent; @@ -100,6 +101,7 @@ public class ActuallyAdditions { ActuallyContainers.CONTAINERS.register(eventBus); ENTITIES.register(eventBus); eventBus.addListener(this::onConfigReload); + ActuallyParticles.init(eventBus); MinecraftForge.EVENT_BUS.addListener(this::serverStarted); MinecraftForge.EVENT_BUS.addListener(this::serverStopped); @@ -110,6 +112,7 @@ public class ActuallyAdditions { eventBus.addListener(this::setup); eventBus.addListener(this::clientSetup); + eventBus.addListener(this::particleFactoryRegister); IFarmerBehavior.initBehaviors(); } @@ -152,6 +155,10 @@ public class ActuallyAdditions { ActuallyAdditionsClient.setup(event); } + private void particleFactoryRegister(ParticleFactoryRegisterEvent event) { + ActuallyAdditionsClient.registerParticleFactories(); + } + public void serverStarted(FMLServerStartedEvent event) { // TODO: [port] check if this is needed diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java index 554d92d14..a5f00e2ea 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java @@ -12,22 +12,19 @@ package de.ellpeck.actuallyadditions.mod; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.render.*; -import de.ellpeck.actuallyadditions.mod.entity.EntityWorm; -import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.entity.RenderWorm; import de.ellpeck.actuallyadditions.mod.event.ClientEvents; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers; import de.ellpeck.actuallyadditions.mod.inventory.gui.*; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import de.ellpeck.actuallyadditions.mod.items.ItemWorm; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; +import de.ellpeck.actuallyadditions.mod.particle.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.network.play.ClientPlayNetHandler; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; -import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.ItemModelsProperties; import net.minecraft.network.play.client.CPlayerDiggingPacket; import net.minecraft.util.ResourceLocation; @@ -37,7 +34,6 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; public class ActuallyAdditionsClient { @@ -75,8 +71,8 @@ public class ActuallyAdditionsClient { setupSpecialRenders(); event.enqueueWork(() -> - ItemModelsProperties.register(ActuallyItems.WORM.get(), new ResourceLocation(ActuallyAdditions.MODID, "snail"), - (stack, world, entity) -> "snail mail".equalsIgnoreCase(stack.getHoverName().getString()) ? 1F : 0F)); + ItemModelsProperties.register(ActuallyItems.WORM.get(), new ResourceLocation(ActuallyAdditions.MODID, "snail"), + (stack, world, entity) -> "snail mail".equalsIgnoreCase(stack.getHoverName().getString()) ? 1F : 0F)); setupRenderLayers(); } @@ -113,6 +109,11 @@ public class ActuallyAdditionsClient { RenderingRegistry.registerEntityRenderingHandler(ActuallyAdditions.ENTITY_WORM.get(), RenderWorm::new); } + public static void registerParticleFactories() { + Minecraft.getInstance().particleEngine.register(ActuallyParticles.LASER_ITEM.get(), ParticleLaserItem.Factory::new); + Minecraft.getInstance().particleEngine.register(ActuallyParticles.BEAM.get(), ParticleBeam.Factory::new); + } + // TODO: [port] validate that this works public static void sendBreakPacket(BlockPos pos) { ClientPlayNetHandler connection = Minecraft.getInstance().getConnection(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterface.java index 99ead10a8..66cba7948 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterface.java @@ -26,8 +26,14 @@ public class BlockItemInterface extends BlockContainerBase { super(ActuallyBlocks.defaultPickProps(0)); } - //@Override - public TileEntity newBlockEntity(IBlockReader worldIn) { + @Override + public boolean hasTileEntity(BlockState state) { + return true; + } + + @Nullable + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new TileEntityItemInterface(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java index ce6a08052..8ca38b568 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java @@ -28,7 +28,7 @@ public class BlockItemInterfaceHopping extends BlockItemInterface { return Shapes.HOPPING_ITEM_VIEWER_SHAPE; } - @Override + //@Override public TileEntity newBlockEntity(IBlockReader worldIn) { return new TileEntityItemInterfaceHopping(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 6185c464b..95bbe5c2b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.blocks; import com.mojang.blaze3d.matrix.MatrixStack; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock; @@ -20,9 +21,16 @@ import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.items.ItemEngineerGoggles; import de.ellpeck.actuallyadditions.mod.items.ItemLaserRelayUpgrade; import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench; -import de.ellpeck.actuallyadditions.mod.tile.*; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergyAdvanced; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergyExtreme; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayFluids; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemAdvanced; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import io.netty.util.internal.ConcurrentSet; import net.minecraft.block.BlockState; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; @@ -42,6 +50,9 @@ import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import java.util.ArrayList; +import java.util.List; + public class BlockLaserRelay extends FullyDirectionalBlock.Container implements IHudDisplay { @@ -146,8 +157,13 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements return ActionResultType.FAIL; } - //@Override - public TileEntity newBlockEntity(IBlockReader world) { + @Override + public boolean hasTileEntity(BlockState state) { + return true; + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { switch (this.type) { case ITEM: return new TileEntityLaserRelayItem(); @@ -200,11 +216,27 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements @Override public void onRemove(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { - super.onRemove(state, world, pos, newState, isMoving); - if (state != newState) { + ConcurrentSet connectionPairs = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(pos, world); ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(pos, world); + List relayPositions = new ArrayList<>(); + connectionPairs.forEach(pair -> { + for (BlockPos pairPos : pair.getPositions()) { + if (!pos.equals(pairPos)) { + relayPositions.add(pairPos); + } + } + }); + //Update the connected relays to sync the changes to the client + relayPositions.forEach(relayPos -> { + TileEntity tile = world.getBlockEntity(relayPos); + if(tile instanceof TileEntityLaserRelay) { + TileEntityLaserRelay relay = (TileEntityLaserRelay) tile; + relay.sendUpdate(); + } + }); } + super.onRemove(state, world, pos, newState, isMoving); } // // @Override @@ -225,6 +257,19 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return Shapes.RELAY_SHAPE; + switch (state.getValue(FACING)) { + case UP: + return Shapes.LaserRelayShapes.SHAPE_U; + case DOWN: + return Shapes.LaserRelayShapes.SHAPE_D; + case EAST: + return Shapes.LaserRelayShapes.SHAPE_E; + case SOUTH: + return Shapes.LaserRelayShapes.SHAPE_S; + case WEST: + return Shapes.LaserRelayShapes.SHAPE_W; + default: + return Shapes.LaserRelayShapes.SHAPE_N; + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/Shapes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/Shapes.java index e5544e09f..5acc6e6d6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/Shapes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/Shapes.java @@ -135,6 +135,15 @@ public class Shapes { .add(15, 1, 0, 16, 15, 1) .standardReduceBuild().get(); + static final class LaserRelayShapes { + static final VoxelShape SHAPE_U = Stream.of(Block.box(1, 0, 1, 15, 1, 15), Block.box(3, 1, 3, 13, 5, 13), Block.box(7, 4, 7, 9, 10, 9)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + static final VoxelShape SHAPE_D = Stream.of(Block.box(1, 15, 1, 15, 16, 15), Block.box(3, 11, 3, 13, 15, 13), Block.box(7, 6, 7, 9, 12, 9)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + static final VoxelShape SHAPE_N = Stream.of(Block.box(1, 1, 15, 15, 15, 16), Block.box(3, 3, 11, 13, 13, 15), Block.box(7, 7, 6, 9, 9, 12)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + static final VoxelShape SHAPE_E = Stream.of(Block.box(0, 1, 1, 1, 15, 15), Block.box(1, 3, 3, 5, 13, 13), Block.box(4, 7, 7, 10, 9, 9)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + static final VoxelShape SHAPE_S = Stream.of(Block.box(1, 1, 0, 15, 15, 1), Block.box(3, 3, 1, 13, 13, 5), Block.box(7, 7, 4, 9, 9, 10)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + static final VoxelShape SHAPE_W = Stream.of(Block.box(15, 1, 1, 16, 15, 15), Block.box(11, 3, 3, 15, 13, 13), Block.box(6, 7, 7, 12, 9, 9)).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get(); + } + public static class ShapeBuilder { Stream.Builder shapes = Stream.builder(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java index 9db989782..bfe150fd2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.blocks.render; import com.mojang.blaze3d.matrix.MatrixStack; -import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.LaserType; import de.ellpeck.actuallyadditions.mod.config.ConfigValues; @@ -22,23 +21,28 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import io.netty.util.internal.ConcurrentSet; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; +import net.minecraft.util.Rotation; import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; public class RenderLaserRelay extends TileEntityRenderer { - private static final float[] COLOR = new float[]{1F, 0F, 0F}; - private static final float[] COLOR_ITEM = new float[]{0F, 124F / 255F, 16F / 255F}; - private static final float[] COLOR_FLUIDS = new float[]{0F, 97F / 255F, 198F / 255F}; - private static final float[] COLOR_INFRARED = new float[]{209F / 255F, 179F / 255F, 239F / 255F}; + private static final int COLOR = 16711680; + private static final int COLOR_ITEM = 31760; + private static final int COLOR_FLUIDS = 25030; + private static final int COLOR_INFRARED = 13743087; public RenderLaserRelay(TileEntityRendererDispatcher rendererDispatcherIn) { super(rendererDispatcherIn); @@ -47,6 +51,7 @@ public class RenderLaserRelay extends TileEntityRenderer { @Override public void render(TileEntityLaserRelay tile, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) { TileEntityLaserRelay relay = tile; + BlockState state = tile.getBlockState(); boolean hasInvis = false; PlayerEntity player = Minecraft.getInstance().player; @@ -61,13 +66,15 @@ public class RenderLaserRelay extends TileEntityRenderer { ItemStack hand = player.getMainHandItem(); if (hasGoggles || StackUtil.isValid(hand) && (hand.getItem() == ConfigValues.itemCompassConfigurator || hand.getItem() instanceof ItemLaserWrench) || "themattabase".equals(player.getName().getString())) { matrices.pushPose(); + Direction direction = state.hasProperty(BlockStateProperties.FACING) ? + state.getValue(BlockStateProperties.FACING) : Direction.UP; - float yTrans = 0.2f; //tile.getBlockMetadata() == 0 ? 0.2F : 0.8F; // TODO: [port][fix] no clue what this is + float yTrans = direction.getAxis() == Direction.Axis.Y ? 0.2f : 0.8F; //tile.getBlockMetadata() == 0 ? 0.2F : 0.8F; // TODO: [port][fix] no clue what this is matrices.translate(0.5F, yTrans, 0.5F); matrices.scale(0.2F, 0.2F, 0.2F); double boop = Util.getMillis() / 800D; - matrices.mulPose(new Quaternion((float) (boop * 40D % 360), 0, 1, 0)); // TODO: [port][test] this might not work + matrices.mulPose(Vector3f.YP.rotationDegrees((float) (boop * 40D % 360))); AssetUtil.renderItemInWorld(upgrade, combinedLight, combinedOverlay, matrices, buffer); @@ -75,7 +82,7 @@ public class RenderLaserRelay extends TileEntityRenderer { } } - ConcurrentSet connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(tile.getBlockPos(), tile.getLevel()); + ConcurrentSet connections = tile.getConnections(); if (connections != null && !connections.isEmpty()) { for (IConnectionPair pair : connections) { if (!pair.doesSuppressRender() && tile.getBlockPos().equals(pair.getPositions()[0])) { @@ -88,17 +95,26 @@ public class RenderLaserRelay extends TileEntityRenderer { boolean otherInvis = StackUtil.isValid(secondUpgrade) && secondUpgrade.getItem() == ActuallyItems.LASER_UPGRADE_INVISIBILITY.get(); if (hasGoggles || !hasInvis || !otherInvis) { - float[] color = hasInvis && otherInvis - ? COLOR_INFRARED - : relay.type == LaserType.ITEM - ? COLOR_ITEM - : relay.type == LaserType.FLUID - ? COLOR_FLUIDS - : COLOR; + int color = hasInvis && otherInvis + ? COLOR_INFRARED : relay.type == LaserType.ITEM + ? COLOR_ITEM : relay.type == LaserType.FLUID + ? COLOR_FLUIDS : COLOR; - AssetUtil.renderLaser(first.getX() + 0.5, first.getY() + 0.5, first.getZ() + 0.5, second.getX() + 0.5, second.getY() + 0.5, second.getZ() + 0.5, 120, hasInvis && otherInvis - ? 0.1F - : 0.35F, 0.05, color); + BlockPos offsetStart = first.subtract(tile.getBlockPos()); + BlockPos offsetEnd = second.subtract(tile.getBlockPos()); + offsetEnd = offsetEnd.rotate(Rotation.CLOCKWISE_90); + + matrices.pushPose(); + + AssetUtil.renderLaser(matrices, buffer, + new Vector3d(offsetStart.getX(), offsetStart.getY(), offsetStart.getZ()), + new Vector3d(offsetEnd.getX(), offsetEnd.getY(), offsetEnd.getZ()), + 120, color, + hasInvis && otherInvis + ? 0.1F + : 0.35F, 0.05F); + + matrices.popPose(); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java index 90890a2b7..311cadef8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java @@ -39,6 +39,7 @@ public class CommonConfig { public static ForgeConfigSpec.IntValue RECONSTRUCTOR_POWER; public static ForgeConfigSpec.IntValue OIL_GENERATOR_TRANSFER; public static ForgeConfigSpec.IntValue MINER_LENS_ENERGY; + public static ForgeConfigSpec.BooleanValue LASER_RELAY_LOSS; public static void build() { BUILDER.comment("Machine Settings").push("machineSettings"); @@ -47,6 +48,7 @@ public class CommonConfig { RECONSTRUCTOR_POWER = BUILDER.comment("The amount of power the atomic reconstructor can store.").defineInRange("reconstructorPower", 300000, 300000, Integer.MAX_VALUE); OIL_GENERATOR_TRANSFER = BUILDER.comment("The amount of power the oil generator can transfer per tick.").defineInRange("oilGeneratorTransfer", 500, 100, Integer.MAX_VALUE); MINER_LENS_ENERGY = BUILDER.comment("The energy use of the Atomic Reconstructor's Mining Lens.").defineInRange("minerLensEnergy", 60000, 1, Integer.MAX_VALUE); + LASER_RELAY_LOSS = BUILDER.comment("If Energy Laser Relays should have energy loss.").define("laserRelayLoss", true); BUILDER.pop(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java index 8bbdc9456..d04dc1769 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java @@ -96,8 +96,8 @@ public final class ActuallyItems { public static final RegistryObject ENGINEERS_GOGGLES_ADVANCED = ITEMS.register("engineers_goggles_advanced", () -> new ItemEngineerGoggles(true)); public static final RegistryObject ENGINEERS_GOGGLES = ITEMS.register("engineers_goggles", () -> new ItemEngineerGoggles(false)); - public static final RegistryObject LASER_UPGRADE_RANGE = ITEMS.register("laser_upgrade_range", ItemBase::new); - public static final RegistryObject LASER_UPGRADE_INVISIBILITY = ITEMS.register("laser_upgrade_invisibility", ItemBase::new); + public static final RegistryObject LASER_UPGRADE_RANGE = ITEMS.register("laser_upgrade_range", ItemLaserRelayUpgrade::new); + public static final RegistryObject LASER_UPGRADE_INVISIBILITY = ITEMS.register("laser_upgrade_invisibility", ItemLaserRelayUpgrade::new); public static final Supplier HANDHELD_FILLER = ITEMS.register("handheld_filler", ItemFillingWand::new); public static final RegistryObject TRAVELERS_SACK = ITEMS.register("travelers_sack", () -> new ItemBag(false)); public static final RegistryObject VOID_SACK = ITEMS.register("void_sack", () -> new ItemBag(true)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/LaserRelayConnectionHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/LaserRelayConnectionHandler.java index 22df52945..6be542211 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/LaserRelayConnectionHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/LaserRelayConnectionHandler.java @@ -70,13 +70,15 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH @Override public ConcurrentSet getConnectionsFor(BlockPos relay, World world) { ConcurrentSet allPairs = new ConcurrentSet<>(); -/* for (Network aNetwork : WorldData.get(world).laserRelayNetworks) { - for (IConnectionPair pair : aNetwork.connections) { - if (pair.contains(relay)) { - allPairs.add(pair); + if(!world.isClientSide) { + for (Network aNetwork : WorldData.get(world).laserRelayNetworks) { + for (IConnectionPair pair : aNetwork.connections) { + if (pair.contains(relay)) { + allPairs.add(pair); + } } } - }*/ //TODO ohhh boy + } //TODO ohhh boy return allPairs; } @@ -107,7 +109,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH */ @Override public Network getNetworkFor(BlockPos relay, World world) { - if (world != null) { + if (world != null && !world.isClientSide) { for (Network aNetwork : WorldData.get(world).laserRelayNetworks) { for (IConnectionPair pair : aNetwork.connections) { if (pair.contains(relay)) { @@ -135,7 +137,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH @Override public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender, boolean removeIfConnected) { - if (firstRelay == null || secondRelay == null || firstRelay == secondRelay || firstRelay.equals(secondRelay)) { + if (world.isClientSide || firstRelay == null || secondRelay == null || firstRelay == secondRelay || firstRelay.equals(secondRelay)) { return false; } WorldData data = WorldData.get(world); @@ -184,7 +186,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH @Override public void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay) { - if (world != null && firstRelay != null && secondRelay != null) { + if (world != null && !world.isClientSide && firstRelay != null && secondRelay != null) { Network network = this.getNetworkFor(firstRelay, world); if (network != null) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 2e68f2d2c..6ae8a06dd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -20,14 +20,12 @@ import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.Particle; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.NBTUtil; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.RegistryKey; import net.minecraft.util.ResourceLocation; @@ -84,8 +82,11 @@ public final class PacketHandler { double outY = compound.getDouble("OutY") + 0.525; double outZ = compound.getDouble("OutZ") + 0.5; - Particle fx = new ParticleLaserItem(mc.level, outX, outY, outZ, stack, 0.025, inX, inY, inZ); +// Particle fx = new ParticleLaserItem(mc.level, outX, outY, outZ, stack, 0.025, inX, inY, inZ); //mc.effectRenderer.addEffect(fx); //TODO + + mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, outX, outY, outZ), + inX, inY, inZ, 0, 0.025, 0); } }; public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java new file mode 100644 index 000000000..4fd0d68ce --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java @@ -0,0 +1,20 @@ +package de.ellpeck.actuallyadditions.mod.particle; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import net.minecraft.particles.ParticleType; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; + +public class ActuallyParticles { + private static final DeferredRegister> PARTICLE_TYPES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, ActuallyAdditions.MODID); + + + public static final RegistryObject> LASER_ITEM = PARTICLE_TYPES.register("laser_item", LaserItemParticleType::new); + public static final RegistryObject> BEAM = PARTICLE_TYPES.register("beam", BeamParticleType::new); + + public static void init(IEventBus evt) { + PARTICLE_TYPES.register(evt); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleData.java new file mode 100644 index 000000000..f60d5ec5f --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleData.java @@ -0,0 +1,136 @@ +package de.ellpeck.actuallyadditions.mod.particle; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.PacketBuffer; +import net.minecraft.particles.IParticleData; +import net.minecraft.particles.ParticleType; + +import java.util.Locale; + +public class BeamParticleData extends ParticleType implements IParticleData { + private ParticleType type; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.DOUBLE.fieldOf("endX").forGetter(d -> d.endX), + Codec.DOUBLE.fieldOf("endY").forGetter(d -> d.endY), + Codec.DOUBLE.fieldOf("endZ").forGetter(d -> d.endZ), + Codec.FLOAT.fieldOf("r").forGetter(d -> d.color[0]), + Codec.FLOAT.fieldOf("g").forGetter(d -> d.color[1]), + Codec.FLOAT.fieldOf("b").forGetter(d -> d.color[2]), + Codec.FLOAT.fieldOf("alpha").forGetter(d -> d.alpha), + Codec.INT.fieldOf("maxAge").forGetter(d -> d.maxAge), + Codec.DOUBLE.fieldOf("rotationTime").forGetter(d -> d.rotationTime), + Codec.FLOAT.fieldOf("size").forGetter(d -> d.size) + ) + .apply(instance, BeamParticleData::new)); + protected final double endX, endY, endZ; + protected final float[] color = new float[3]; + protected final float alpha; + protected final int maxAge; + protected final double rotationTime; + protected final float size; + @SuppressWarnings("deprecation") + static final IDeserializer DESERIALIZER = new IDeserializer() { + + @Override + public BeamParticleData fromCommand(ParticleType type, StringReader reader) throws CommandSyntaxException { + reader.expect(' '); + double endX = reader.readDouble(); + reader.expect(' '); + double endY = reader.readDouble(); + reader.expect(' '); + double endZ = reader.readDouble(); + reader.expect(' '); + float red = (float) reader.readDouble(); + reader.expect(' '); + float green = (float) reader.readDouble(); + reader.expect(' '); + float blue = (float) reader.readDouble(); + reader.expect(' '); + float alpha = (float) reader.readDouble(); + reader.expect(' '); + int maxAge = reader.readInt(); + reader.expect(' '); + double rotationTime = reader.readDouble(); + reader.expect(' '); + float size = (float) reader.readDouble(); + return new BeamParticleData(type, endX, endY, endZ, red, green, blue, alpha, maxAge, rotationTime, size); + } + + @Override + public BeamParticleData fromNetwork(ParticleType type, PacketBuffer buffer) { + double endX = buffer.readDouble(); + double endY = buffer.readDouble(); + double endZ = buffer.readDouble(); + float red = buffer.readFloat(); + float green = buffer.readFloat(); + float blue = buffer.readFloat(); + float alpha = buffer.readFloat(); + int maxAge = buffer.readInt(); + double rotationTime = buffer.readDouble(); + float size = buffer.readFloat(); + + return new BeamParticleData(type, endX, endY, endZ, red, green, blue, alpha, maxAge, rotationTime, size); + } + }; + + public BeamParticleData(ParticleType particleTypeData, + double endX, double endY, double endZ, float red, float green, float blue, float alpha, + int maxAge, double rotationTime, float size) { + super(false, DESERIALIZER); + this.type = particleTypeData; + this.endX = endX; + this.endY = endY; + this.endZ = endZ; + this.color[0] = red; + this.color[1] = green; + this.color[2] = blue; + this.alpha = alpha; + this.maxAge = maxAge; + this.rotationTime = rotationTime; + this.size = size; + } + + public BeamParticleData(double endX, double endY, double endZ, float red, float green, float blue, float alpha, + int maxAge, double rotationTime, float size) { + this(ActuallyParticles.BEAM.get(), endX, endY, endZ, red, green, blue, alpha, maxAge, rotationTime, size); + } + + public BeamParticleData(double endX, double endY, double endZ, float[] color, float alpha, + int maxAge, double rotationTime, float size) { + this(ActuallyParticles.BEAM.get(), endX, endY, endZ, color[0], color[1], color[2], alpha, maxAge, rotationTime, size); + } + + @Override + public ParticleType getType() { + return type; + } + + @Override + public void writeToNetwork(PacketBuffer buffer) { + buffer.writeDouble(this.endX); + buffer.writeDouble(this.endY); + buffer.writeDouble(this.endZ); + buffer.writeFloat(this.color[0]); + buffer.writeFloat(this.color[1]); + buffer.writeFloat(this.color[2]); + buffer.writeFloat(this.alpha); + buffer.writeInt(this.maxAge); + buffer.writeDouble(this.rotationTime); + buffer.writeFloat(this.size); + } + + @Override + public String writeToString() { + return String.format(Locale.ROOT, "%s %.2f %.2f %.2f, %.2f %.2f %.2f %.2f %d %.2f %.2f", + this.endX, this.endY, this.endZ, this.color[0], this.color[1], this.color[2], this.alpha, + this.maxAge, this.rotationTime, this.size); + } + + @Override + public Codec codec() { + return BeamParticleData.CODEC; + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleType.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleType.java new file mode 100644 index 000000000..8de37e7b5 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/BeamParticleType.java @@ -0,0 +1,15 @@ +package de.ellpeck.actuallyadditions.mod.particle; + +import com.mojang.serialization.Codec; +import net.minecraft.particles.ParticleType; + +public class BeamParticleType extends ParticleType { + public BeamParticleType() { + super(false, BeamParticleData.DESERIALIZER); + } + + @Override + public Codec codec() { + return BeamParticleData.CODEC; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java new file mode 100644 index 000000000..30c94a181 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java @@ -0,0 +1,95 @@ +package de.ellpeck.actuallyadditions.mod.particle; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraft.particles.IParticleData; +import net.minecraft.particles.ParticleType; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.Locale; + +public class LaserItemParticleData extends ParticleType implements IParticleData { + private ParticleType type; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ItemStack.CODEC.fieldOf("stack").forGetter(d -> d.stack), + Codec.DOUBLE.fieldOf("outputX").forGetter(d -> d.outputX), + Codec.DOUBLE.fieldOf("outputY").forGetter(d -> d.outputY), + Codec.DOUBLE.fieldOf("outputZ").forGetter(d -> d.outputZ) + ) + .apply(instance, LaserItemParticleData::new)); + protected final ItemStack stack; + protected final double outputX, outputY, outputZ; + @SuppressWarnings("deprecation") + static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { + + @Override + public LaserItemParticleData fromCommand(ParticleType type, StringReader reader) throws CommandSyntaxException { + reader.expect(' '); + String itemString = reader.readString(); + ResourceLocation itemLocation = ResourceLocation.tryParse(itemString); + Item item = itemLocation == null ? null : ForgeRegistries.ITEMS.getValue(itemLocation); + ItemStack stack = item == null ? ItemStack.EMPTY : new ItemStack(item); + reader.expect(' '); + double outputX = reader.readDouble(); + reader.expect(' '); + double outputY = reader.readDouble(); + reader.expect(' '); + double outputZ = reader.readDouble(); + return new LaserItemParticleData(type, stack, outputX, outputY, outputZ); + } + + @Override + public LaserItemParticleData fromNetwork(ParticleType type, PacketBuffer buffer) { + ItemStack stack = buffer.readItem(); + double outputX = buffer.readDouble(); + double outputY = buffer.readDouble(); + double outputZ = buffer.readDouble(); + return new LaserItemParticleData(type, stack, outputX, outputY, outputZ); + } + }; + + public LaserItemParticleData(ParticleType particleTypeData, ItemStack stack, + double outputX, double outputY, double outputZ) { + super(false, DESERIALIZER); + this.type = particleTypeData; + this.stack = stack; + this.outputX = outputX; + this.outputY = outputY; + this.outputZ = outputZ; + } + + public LaserItemParticleData(ItemStack stack, double outputX, double outputY, double outputZ) { + this(ActuallyParticles.LASER_ITEM.get(), stack, outputX, outputY, outputZ); + } + + @Override + public ParticleType getType() { + return type; + } + + @Override + public void writeToNetwork(PacketBuffer buffer) { + buffer.writeItemStack(this.stack, true); + buffer.writeDouble(this.outputX); + buffer.writeDouble(this.outputY); + buffer.writeDouble(this.outputZ); + } + + @Override + public String writeToString() { + return String.format(Locale.ROOT, "%s %s %.2f %.2f %.2f", ForgeRegistries.PARTICLE_TYPES.getKey(this.getType()), + ForgeRegistries.ITEMS.getKey(this.stack.getItem()), + this.outputX, this.outputY, this.outputZ); + } + + @Override + public Codec codec() { + return LaserItemParticleData.CODEC; + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleType.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleType.java new file mode 100644 index 000000000..bc8a7f6ef --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleType.java @@ -0,0 +1,15 @@ +package de.ellpeck.actuallyadditions.mod.particle; + +import com.mojang.serialization.Codec; +import net.minecraft.particles.ParticleType; + +public class LaserItemParticleType extends ParticleType { + public LaserItemParticleType() { + super(false, LaserItemParticleData.DESERIALIZER); + } + + @Override + public Codec codec() { + return LaserItemParticleData.CODEC; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleBeam.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleBeam.java index dd957e6c3..f2f9af4af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleBeam.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleBeam.java @@ -12,10 +12,13 @@ package de.ellpeck.actuallyadditions.mod.particle; import com.mojang.blaze3d.vertex.IVertexBuilder; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.client.particle.IAnimatedSprite; +import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.Particle; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.world.ClientWorld; +import net.minecraft.particles.IParticleData; public class ParticleBeam extends Particle { @@ -27,7 +30,8 @@ public class ParticleBeam extends Particle { private final float size; private final float alpha; - public ParticleBeam(ClientWorld world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) { + public ParticleBeam(ClientWorld world, double startX, double startY, double startZ, double endX, double endY, double endZ, + float[] color, float alpha, int maxAge, double rotationTime, float size) { super(world, startX, startY, startZ); this.endX = endX; this.endY = endY; @@ -50,4 +54,22 @@ public class ParticleBeam extends Particle { public IParticleRenderType getRenderType() { return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } + + + public static class Factory implements IParticleFactory { + public Factory(IAnimatedSprite sprite) { + + } + + @Override + public Particle createParticle(BeamParticleData data, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + return new ParticleBeam(worldIn, x, y, z, data.endX, data.endY, data.endZ, data.color, data.alpha, data.maxAge, + data.rotationTime, data.size); + } + + public static IParticleData createData(double endX, double endY, double endZ, float[] color, float alpha, + int maxAge, double rotationTime, float size) { + return new BeamParticleData(endX, endY, endZ, color, alpha, maxAge, rotationTime, size); + } + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleLaserItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleLaserItem.java index e5a1b3e60..e2fe83721 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleLaserItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleLaserItem.java @@ -10,20 +10,29 @@ package de.ellpeck.actuallyadditions.mod.particle; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.IVertexBuilder; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.IAnimatedSprite; +import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.Particle; import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.world.ClientWorld; import net.minecraft.item.ItemStack; +import net.minecraft.particles.IParticleData; import net.minecraft.util.Util; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; -import org.lwjgl.opengl.GL14; +import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.world.LightType; public class ParticleLaserItem extends Particle { private final double otherX; @@ -56,40 +65,65 @@ public class ParticleLaserItem extends Particle { super.remove(); if (this.otherX != 0 || this.otherY != 0 || this.otherZ != 0) { - Particle fx = new ParticleLaserItem(this.level, this.otherX, this.otherY, this.otherZ, this.stack, -0.025); - Minecraft.getInstance().particleEngine.add(fx); + this.level.addParticle(Factory.createData(this.stack, 0, 0, 0), + this.otherX, this.otherY, this.otherZ, 0, -0.025, 0); } } @Override public void render(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) { + Minecraft mc = Minecraft.getInstance(); + IRenderTypeBuffer.Impl renderBuffer = mc.renderBuffers().bufferSource(); + Vector3d cam = renderInfo.getPosition(); + RenderSystem.pushMatrix(); RenderHelper.turnBackOn(); + MatrixStack matrices = new MatrixStack(); + matrices.pushPose(); - Vector3d cam = renderInfo.getPosition(); - RenderSystem.translated(this.x - cam.x(), this.y - cam.y(), this.z - cam.z()); - RenderSystem.scalef(0.3F, 0.3F, 0.3F); + matrices.translate(x - cam.x, y - cam.y, z - cam.z); + matrices.scale(0.3F, 0.3F, 0.3F); double boop = Util.getMillis() / 600D; - RenderSystem.rotatef((float) (boop * 40D % 360), 0, 1, 0); + matrices.mulPose(Vector3f.YP.rotationDegrees((float) (boop * 40D % 360))); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA.value, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.value, GlStateManager.SourceFactor.ONE.value, GlStateManager.DestFactor.ZERO.value); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); float ageRatio = (float) this.age / (float) this.lifetime; float color = this.yd < 0 - ? 1F - ageRatio - : ageRatio; - GL14.glBlendColor(color, color, color, color); + ? 1F - ageRatio + : ageRatio; + RenderSystem.blendColor(color, color, color, color); - AssetUtil.renderItemWithoutScrewingWithColors(this.stack); + int blockLight = level.getBrightness(LightType.BLOCK, new BlockPos(x, y, z)); + int skyLight = level.getBrightness(LightType.SKY, new BlockPos(x, y, z)); + AssetUtil.renderItemWithoutScrewingWithColors(this.stack, matrices, LightTexture.pack(blockLight, skyLight), OverlayTexture.NO_OVERLAY); RenderHelper.turnOff(); + matrices.popPose(); RenderSystem.popMatrix(); + renderBuffer.endBatch(); } @Override public IParticleRenderType getRenderType() { return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } + + public static class Factory implements IParticleFactory { + public Factory(IAnimatedSprite sprite) { + + } + + @Override + public Particle createParticle(LaserItemParticleData data, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + return new ParticleLaserItem(worldIn, x, y, z, data.stack, ySpeed, data.outputX, data.outputY, data.outputZ); + } + + public static IParticleData createData(ItemStack stack, double outputX, double outputY, double outputZ) { + return new LaserItemParticleData(stack, outputX, outputY, outputZ); + } + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index 9b1c68520..3eaea8908 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -42,6 +42,8 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { private Network cachedNetwork; private int changeAmountAtCaching = -1; private int lastRange; + // List of connections that are synced to the client for RenderLaserRelay to use + private final ConcurrentSet connections = new ConcurrentSet<>(); public TileEntityLaserRelay(TileEntityType tileType, LaserType type) { super(tileType, 1); @@ -55,10 +57,12 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { if (type == NBTType.SYNC) { ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.worldPosition, this.level); + this.connections.clear(); ListNBT list = compound.getList("Connections", 10); if (!list.isEmpty()) { for (int i = 0; i < list.size(); i++) { ConnectionPair pair = new ConnectionPair(); + this.connections.add(pair); pair.readFromNBT(list.getCompound(i)); ActuallyAdditionsAPI.connectionHandler.addConnection(pair.getPositions()[0], pair.getPositions()[1], this.type, this.level, pair.doesSuppressRender()); } @@ -97,6 +101,7 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { for (IConnectionPair pair : connections) { int distanceSq = (int) pair.getPositions()[0].distSqr(pair.getPositions()[1]); if (distanceSq > range * range) { + this.connections.remove(pair); ActuallyAdditionsAPI.connectionHandler.removeConnection(this.level, pair.getPositions()[0], pair.getPositions()[1]); } } @@ -184,4 +189,8 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { public abstract String getCompassDisplayString(); public abstract void onCompassAction(PlayerEntity player); + + public ConcurrentSet getConnections() { + return connections; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index dca085eaa..264f142a9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -15,7 +15,7 @@ import de.ellpeck.actuallyadditions.api.laser.LaserType; import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; -import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; +import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.minecraft.entity.player.PlayerEntity; @@ -186,8 +186,8 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { if (totalReceiverAmount > 0 && !relaysThatWork.isEmpty()) { int amountPer = maxTransfer / totalReceiverAmount <= 0 - ? maxTransfer / totalReceiverAmount - : maxTransfer; + ? maxTransfer + : maxTransfer / totalReceiverAmount; for (TileEntityLaserRelayEnergy theRelay : relaysThatWork) { double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage()); @@ -231,7 +231,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { } private int calcDeduction(int theoreticalReceived, double highestLoss) { - return ConfigBoolValues.LASER_RELAY_LOSS.isEnabled() + return CommonConfig.Machines.LASER_RELAY_LOSS.get() ? MathHelper.ceil(theoreticalReceived * (highestLoss / 100)) : 0; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index dcd7b1844..ede321c65 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.util; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.IVertexBuilder; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes; @@ -23,9 +24,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemCameraTransforms; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -38,6 +44,7 @@ import net.minecraft.util.math.vector.Vector3f; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.fml.network.PacketDistributor; public final class AssetUtil { @@ -93,28 +100,29 @@ public final class AssetUtil { // } @OnlyIn(Dist.CLIENT) - public static void renderItemWithoutScrewingWithColors(ItemStack stack) { -/* if (StackUtil.isValid(stack)) { + public static void renderItemWithoutScrewingWithColors(ItemStack stack, MatrixStack matrices, int combinedOverlay, int combinedLight) { + if (StackUtil.isValid(stack)) { Minecraft mc = Minecraft.getInstance(); ItemRenderer renderer = mc.getItemRenderer(); TextureManager manager = mc.getTextureManager(); + IRenderTypeBuffer.Impl irendertypebuffer$impl = mc.renderBuffers().bufferSource(); - IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null); - - manager.bind(TextureMap.LOCATION_BLOCKS_TEXTURE); - manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false); - GlStateManager._enableRescaleNormal(); - GlStateManager._enableBlend(); - GlStateManager._pushMatrix(); - model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.FIXED, false); - renderer.renderItem(stack, model); - GlStateManager.cullFace(GlStateManager.CullFace.BACK); - GlStateManager._popMatrix(); - GlStateManager._disableRescaleNormal(); - GlStateManager._disableBlend(); - manager.bind(TextureMap.LOCATION_BLOCKS_TEXTURE); - manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap(); - }*/ + IBakedModel model = renderer.getModel(stack, null, null); + manager.bind(AtlasTexture.LOCATION_BLOCKS); + manager.getTexture(AtlasTexture.LOCATION_BLOCKS).setBlurMipmap(false, false); + RenderSystem.enableRescaleNormal(); + RenderSystem.enableBlend(); + RenderSystem.pushMatrix(); + model = ForgeHooksClient.handleCameraTransforms(matrices, model, ItemCameraTransforms.TransformType.FIXED, false); + renderer.render(stack, ItemCameraTransforms.TransformType.FIXED, false, matrices, irendertypebuffer$impl, + combinedOverlay, combinedLight, model); + RenderSystem.popMatrix(); + RenderSystem.disableRescaleNormal(); + RenderSystem.disableBlend(); + manager.bind(AtlasTexture.LOCATION_BLOCKS); + manager.getTexture(AtlasTexture.LOCATION_BLOCKS).restoreLastBlurMipmap(); + irendertypebuffer$impl.endBatch(); + } } @OnlyIn(Dist.CLIENT) diff --git a/src/main/resources/assets/actuallyadditions/particles/beam.json b/src/main/resources/assets/actuallyadditions/particles/beam.json new file mode 100644 index 000000000..cd22f4e25 --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/particles/beam.json @@ -0,0 +1,4 @@ +{ + "textures": [ + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/particles/laser_item.json b/src/main/resources/assets/actuallyadditions/particles/laser_item.json new file mode 100644 index 000000000..cd22f4e25 --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/particles/laser_item.json @@ -0,0 +1,4 @@ +{ + "textures": [ + ] +} \ No newline at end of file