From 50ee77bf9952305a443ff3b88cbe21f5fdb0803d Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:11:10 +0200 Subject: [PATCH 1/3] bring over #797 --- .../client/particle/ConduitBreakParticle.java | 92 +++++++++++++++++++ .../enderio/conduits/common/ConduitShape.java | 2 +- .../common/conduit/block/ConduitBlock.java | 5 + .../conduit/block/ConduitBlockEntity.java | 16 +++- .../conduit/type/item/ItemConduitTicker.java | 18 +++- .../conduits/common/init/EIOConduitTypes.java | 6 +- .../base/VacuumMachineBlockEntity.java | 2 + 7 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java diff --git a/src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java b/src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java new file mode 100644 index 0000000000..bc68c7753a --- /dev/null +++ b/src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java @@ -0,0 +1,92 @@ +package com.enderio.conduits.client.particle; + +import com.enderio.api.conduit.ConduitType; +import com.enderio.conduits.common.ConduitShape; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.ParticleEngine; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.TextureSheetParticle; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; + +import java.util.List; + +public class ConduitBreakParticle extends TextureSheetParticle { + private final BlockPos pos; + private final float uo; + private final float vo; + + public ConduitBreakParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, BlockPos pos, ResourceLocation texture) { + super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.pos = pos; + this.setSprite(Minecraft.getInstance().getModelManager().getAtlas(InventoryMenu.BLOCK_ATLAS).getSprite(texture)); + this.gravity = 1.0F; + this.rCol = 0.6F; + this.gCol = 0.6F; + this.bCol = 0.6F; + + this.quadSize /= 2.0F; + this.uo = this.random.nextFloat() * 3.0F; + this.vo = this.random.nextFloat() * 3.0F; + } + + public ParticleRenderType getRenderType() { + return ParticleRenderType.TERRAIN_SHEET; + } + + protected float getU0() { + return this.sprite.getU((this.uo + 1.0F) / 4.0F); + } + + protected float getU1() { + return this.sprite.getU(this.uo / 4.0F); + } + + protected float getV0() { + return this.sprite.getV(this.vo / 4.0F); + } + + protected float getV1() { + return this.sprite.getV((this.vo + 1.0F) / 4.0F); + } + + public int getLightColor(float partialTick) { + int i = super.getLightColor(partialTick); + return i == 0 && this.level.hasChunkAt(this.pos) ? LevelRenderer.getLightColor(this.level, this.pos) : i; + } + + public static void addDestroyEffects(BlockPos pos, ConduitType conduit) { + Level level = Minecraft.getInstance().level; + ParticleEngine engine = Minecraft.getInstance().particleEngine; + List boxes = ConduitShape.CONNECTION.toAabbs(); + double countMult = 1D / boxes.size(); + boxes.forEach(aabb -> { + double sizeX = Math.min(1D, aabb.maxX - aabb.minX); + double sizeY = Math.min(1D, aabb.maxY - aabb.minY); + double sizeZ = Math.min(1D, aabb.maxZ - aabb.minZ); + int xCount = Math.max(2, Mth.ceil(sizeX / 0.25D * countMult)); + int yCount = Math.max(2, Mth.ceil(sizeY / 0.25D * countMult)); + int zCount = Math.max(2, Mth.ceil(sizeZ / 0.25D * countMult)); + + for (int iX = 0; iX < xCount; ++iX) { + for (int iY = 0; iY < yCount; ++iY) { + for (int iZ = 0; iZ < zCount; ++iZ) { + double offX = ((double) iX + 0.5D) / (double) xCount; + double offY = ((double) iY + 0.5D) / (double) yCount; + double offZ = ((double) iZ + 0.5D) / (double) zCount; + double x = pos.getX() + offX * sizeX + aabb.minX; + double y = pos.getY() + offY * sizeY + aabb.minY; + double z = pos.getZ() + offZ * sizeZ + aabb.minZ; + engine.add(new ConduitBreakParticle((ClientLevel) level, x, y, z, offX - 0.5D, offY - 0.5D, offZ - 0.5D, pos, ConduitType.getKey(conduit))); + } + } + } + }); + } +} diff --git a/src/conduits/java/com/enderio/conduits/common/ConduitShape.java b/src/conduits/java/com/enderio/conduits/common/ConduitShape.java index c9f8dab596..9229607057 100644 --- a/src/conduits/java/com/enderio/conduits/common/ConduitShape.java +++ b/src/conduits/java/com/enderio/conduits/common/ConduitShape.java @@ -26,7 +26,7 @@ public class ConduitShape { private final Map, VoxelShape> conduitShapes = new HashMap<>(); private final Map directionShapes = new HashMap<>(); private static final VoxelShape CONNECTOR = Block.box(2.5f, 2.5, 15f, 13.5f, 13.5f, 16f); - private static final VoxelShape CONNECTION = Block.box(6.5f, 6.5f, 9.5, 9.5f, 9.5f, 16); + public static final VoxelShape CONNECTION = Block.box(6.5f, 6.5f, 9.5, 9.5f, 9.5f, 16); private static final VoxelShape CORE = Block.box(6.5f, 6.5f, 6.5f, 9.5f, 9.5f, 9.5f); private VoxelShape totalShape = CORE; diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java index 44ef0976cc..0301c595a0 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java @@ -500,4 +500,9 @@ private int getSignalOutput(DynamicConnectionState dyn, RedstoneConduitData data // endregion private record OpenInformation(Direction direction, ConduitType type) {} + + @Override + protected void spawnDestroyParticles(Level level, Player player, BlockPos pos, BlockState state) { + + } } diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java index 3dd7d2d04c..e51661307c 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java @@ -1,22 +1,23 @@ package com.enderio.conduits.common.conduit.block; import com.enderio.api.UseOnly; +import com.enderio.api.conduit.ConduitData; import com.enderio.api.conduit.ConduitMenuData; import com.enderio.api.conduit.ConduitType; -import com.enderio.api.conduit.ConduitData; import com.enderio.api.conduit.SlotType; import com.enderio.api.conduit.upgrade.ConduitUpgrade; import com.enderio.api.filter.ResourceFilter; import com.enderio.base.common.init.EIOCapabilities; +import com.enderio.conduits.ConduitNBTKeys; +import com.enderio.conduits.client.particle.ConduitBreakParticle; +import com.enderio.conduits.common.ConduitShape; import com.enderio.conduits.common.conduit.ConduitBundle; import com.enderio.conduits.common.conduit.ConduitBundleNetworkDataSlot; +import com.enderio.conduits.common.conduit.ConduitGraphObject; import com.enderio.conduits.common.conduit.RightClickAction; import com.enderio.conduits.common.conduit.SlotData; -import com.enderio.conduits.common.conduit.ConduitGraphObject; -import com.enderio.conduits.ConduitNBTKeys; -import com.enderio.conduits.common.ConduitShape; -import com.enderio.conduits.common.conduit.connection.DynamicConnectionState; import com.enderio.conduits.common.conduit.connection.ConnectionState; +import com.enderio.conduits.common.conduit.connection.DynamicConnectionState; import com.enderio.conduits.common.conduit.connection.StaticConnectionStates; import com.enderio.conduits.common.init.ConduitCapabilities; import com.enderio.conduits.common.menu.ConduitMenu; @@ -348,6 +349,11 @@ public boolean removeType(ConduitType type, boolean shouldDrop) { boolean shouldRemove = bundle.removeType(level, type); removeNeighborConnections(type); updateShape(); + + if (level.isClientSide) { + ConduitBreakParticle.addDestroyEffects(getBlockPos(), type); + } + return shouldRemove; } diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/type/item/ItemConduitTicker.java b/src/conduits/java/com/enderio/conduits/common/conduit/type/item/ItemConduitTicker.java index dbb6bba19c..719f66d15e 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/type/item/ItemConduitTicker.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/type/item/ItemConduitTicker.java @@ -31,13 +31,16 @@ protected void tickCapabilityGraph( toNextExtract: for (CapabilityConnection extract: extracts) { IItemHandler extractHandler = extract.capability; + int extracted = 0; + + nextItem: for (int i = 0; i < extractHandler.getSlots(); i++) { int speed = 4; if (extract.upgrade instanceof ExtractionSpeedUpgrade speedUpgrade) { speed *= (int) Math.pow(2, speedUpgrade.tier()); } - ItemStack extractedItem = extractHandler.extractItem(i, speed, true); + ItemStack extractedItem = extractHandler.extractItem(i, speed - extracted, true); if (extractedItem.isEmpty()) { continue; } @@ -75,11 +78,16 @@ protected void tickCapabilityGraph( ItemStack notInserted = ItemHandlerHelper.insertItem(insert.capability, extractedItem, false); if (notInserted.getCount() < extractedItem.getCount()) { - extractHandler.extractItem(i, extractedItem.getCount() - notInserted.getCount(), false); - if (sidedExtractData.isRoundRobin) { - sidedExtractData.rotatingIndex = insertIndex + 1; + extracted += extractedItem.getCount() - notInserted.getCount(); + extractHandler.extractItem(i, extracted, false); + if (extracted >= speed) { + if (sidedExtractData.isRoundRobin) { + sidedExtractData.rotatingIndex = insertIndex + 1; + } + continue toNextExtract; + } else { + continue nextItem; } - continue toNextExtract; } } } diff --git a/src/conduits/java/com/enderio/conduits/common/init/EIOConduitTypes.java b/src/conduits/java/com/enderio/conduits/common/init/EIOConduitTypes.java index e3bdd04c68..943887c029 100644 --- a/src/conduits/java/com/enderio/conduits/common/init/EIOConduitTypes.java +++ b/src/conduits/java/com/enderio/conduits/common/init/EIOConduitTypes.java @@ -39,13 +39,13 @@ public static ConduitType getById(int id) { CONDUIT_TYPES.register("redstone_conduit", RedstoneConduitType::new); public static final RegistryObject FLUID = - fluidConduit("fluid_conduit", 50, false); + fluidConduit("fluid_conduit", 100, false); public static final RegistryObject FLUID2 = - fluidConduit("pressurized_fluid_conduit", 100, false); + fluidConduit("pressurized_fluid_conduit", 1_000, false); public static final RegistryObject FLUID3 = - fluidConduit("ender_fluid_conduit", 200, true); + fluidConduit("ender_fluid_conduit", 10_000, true); public static final RegistryObject ITEM = CONDUIT_TYPES.register("item_conduit", ItemConduitType::new); diff --git a/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java index b1611e8651..58dca53fb0 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java @@ -6,6 +6,7 @@ import com.enderio.core.common.network.slot.BooleanNetworkDataSlot; import com.enderio.core.common.network.slot.IntegerNetworkDataSlot; import com.enderio.machines.common.io.FixedIOConfig; +import com.enderio.machines.common.io.item.SingleSlotAccess; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.item.ItemEntity; @@ -27,6 +28,7 @@ public abstract class VacuumMachineBlockEntity extends Machine protected static final double SPEED_4 = SPEED * 4; private List> entities = new ArrayList<>(); private Class targetClass; + public static SingleSlotAccess FILTER = new SingleSlotAccess(); protected static final Predicate ITEM_ENTITY_FILTER_TRUE = itemEntity -> true; From 5ca8706b31191ff7e4448970c1ad7f15059ecfdb Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:18:56 +0200 Subject: [PATCH 2/3] bring over new changes --- .../enderio/conduits/client/model/ConduitBlockModel.java | 9 +++++++++ .../enderio/conduits/client/particle/package-info.java | 5 +++++ .../enderio/conduits/common/conduit/ConduitBundle.java | 4 ++-- .../conduits/common/conduit/ConduitGraphObject.java | 4 ++-- .../conduits/common/conduit/block/ConduitBlock.java | 7 +++++-- .../common/conduit/block/ConduitBlockEntity.java | 6 ++++++ 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/conduits/java/com/enderio/conduits/client/particle/package-info.java diff --git a/src/conduits/java/com/enderio/conduits/client/model/ConduitBlockModel.java b/src/conduits/java/com/enderio/conduits/client/model/ConduitBlockModel.java index 9884d1925a..0c7c13485e 100644 --- a/src/conduits/java/com/enderio/conduits/client/model/ConduitBlockModel.java +++ b/src/conduits/java/com/enderio/conduits/client/model/ConduitBlockModel.java @@ -280,6 +280,15 @@ public TextureAtlasSprite getParticleIcon() { return EIOModel.getMissingTexture(); } + @Override + public TextureAtlasSprite getParticleIcon(ModelData data) { + ConduitBundle conduitBundle = data.get(ConduitBlockEntity.BUNDLE_MODEL_PROPERTY); //default particle + if (conduitBundle == null) { + return EIOModel.getMissingTexture(); + } + return sprite(conduitBundle, conduitBundle.getTypes().get(0)); + } + @Override public ItemOverrides getOverrides() { return ItemOverrides.EMPTY; diff --git a/src/conduits/java/com/enderio/conduits/client/particle/package-info.java b/src/conduits/java/com/enderio/conduits/client/particle/package-info.java new file mode 100644 index 0000000000..b7f5e8f34e --- /dev/null +++ b/src/conduits/java/com/enderio/conduits/client/particle/package-info.java @@ -0,0 +1,5 @@ +@javax.annotation.ParametersAreNonnullByDefault +@net.minecraft.MethodsReturnNonnullByDefault +@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault + +package com.enderio.conduits.client.particle; diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/ConduitBundle.java b/src/conduits/java/com/enderio/conduits/common/conduit/ConduitBundle.java index 7e9357060f..f0812a10b5 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/ConduitBundle.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/ConduitBundle.java @@ -107,17 +107,17 @@ public > RightClickAction addType(Level level, ConduitT types.set(index, type); var prevNode = (ConduitGraphObject) nodes.remove(first.get()); - nodes.put(type, node); if (prevNode != null) { + node = new ConduitGraphObject<>(pos, prevNode.getConduitData()); //new node with old data prevNode.getConduitData().onRemoved(type, level, pos); if (!level.isClientSide() && prevNode.getGraph() != null) { prevNode.getGraph().remove(prevNode); } } + nodes.put(type, node); node.getConduitData().onCreated(type, level, pos, player); - connections.values().forEach(connection -> connection.disconnectType(index)); onChanged(); return new RightClickAction.Upgrade(first.get()); diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/ConduitGraphObject.java b/src/conduits/java/com/enderio/conduits/common/conduit/ConduitGraphObject.java index 779636c819..98dfe86ccc 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/ConduitGraphObject.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/ConduitGraphObject.java @@ -45,9 +45,9 @@ public Graph getGraph() { } @Override - public void setGraph(Graph graph) { + public void setGraph(@Nullable Graph graph) { this.graph = graph; - this.wrappedGraph = new WrappedConduitGraph<>(graph); + this.wrappedGraph = graph == null ? null : new WrappedConduitGraph<>(graph); } @Nullable diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java index 0301c595a0..ec12e32e5b 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java @@ -453,11 +453,14 @@ public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, } return true; } + + SoundType soundtype = state.getSoundType(level, pos, player); + level.playSound(player, pos, soundtype.getBreakSound(), SoundSource.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); + if (conduit.removeType(conduitType, !player.getAbilities().instabuild)) { return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid); } - SoundType soundtype = state.getSoundType(level, pos, player); - level.playSound(player, pos, soundtype.getBreakSound(), SoundSource.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); + level.gameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Context.of(player, state)); return false; } diff --git a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java index e51661307c..c254b8b65c 100644 --- a/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java +++ b/src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlockEntity.java @@ -306,8 +306,14 @@ public > Optional> tryConn return Optional.of(conduit.bundle.getNodeFor(type)); } else if (type.getTicker().canConnectTo(level, getBlockPos(), dir)) { + if (bundle.getConnectionState(dir, type) instanceof DynamicConnectionState) { //Already connected + updateConnectionToData(type); + return Optional.empty(); + } connectEnd(dir, type); updateConnectionToData(type); + } else { + this.disconnect(dir, type); } return Optional.empty(); From be69f173bf0c66c5ed3da85226e9a7dd31e629fb Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:49:45 +0200 Subject: [PATCH 3/3] Update VacuumMachineBlockEntity.java --- .../common/blockentity/base/VacuumMachineBlockEntity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java index 58dca53fb0..b1611e8651 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/base/VacuumMachineBlockEntity.java @@ -6,7 +6,6 @@ import com.enderio.core.common.network.slot.BooleanNetworkDataSlot; import com.enderio.core.common.network.slot.IntegerNetworkDataSlot; import com.enderio.machines.common.io.FixedIOConfig; -import com.enderio.machines.common.io.item.SingleSlotAccess; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.item.ItemEntity; @@ -28,7 +27,6 @@ public abstract class VacuumMachineBlockEntity extends Machine protected static final double SPEED_4 = SPEED * 4; private List> entities = new ArrayList<>(); private Class targetClass; - public static SingleSlotAccess FILTER = new SingleSlotAccess(); protected static final Predicate ITEM_ENTITY_FILTER_TRUE = itemEntity -> true;