Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conduit Adjustments #797

Merged
merged 11 commits into from
Sep 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,24 @@ public List<StoredEntityData> getEntries() {

@Override
public StoredEntityData getEntry(int index) {
return null;
if (index < 0 || index >= size()) {
throw new IndexOutOfBoundsException(index);
}

var entries = getEntries();
if (index >= entries.size()) {
return StoredEntityData.EMPTY;
}

return entries.get(index);
}

@Override
public void setEntry(int index, StoredEntityData entry) {
if (index < 0 || index >= size()) {
throw new IndexOutOfBoundsException(index);
}

container.set(componentType, getComponent().withEntities(index, entry));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,20 @@ public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlay
}
super.clicked(pSlotId, pButton, pClickType, pPlayer);
}

@Override
public void doClick(int slotId, int button, ClickType clickType, Player player) {
if (slotId >= 0 && slotId < capability.size()) {
// Only allow PICKUP (click) or QUICK_MOVE (shift + click) events.
if (clickType != ClickType.PICKUP && clickType != ClickType.QUICK_MOVE) {
return;
}

if (capability.getEntry(slotId).hasEntity()) {
capability.setEntry(slotId, StoredEntityData.EMPTY);
}
}

super.doClick(slotId, button, clickType, player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
},
"is_multi_fluid": true,
"texture": "enderio:block/conduit/ender_fluid",
"transfer_rate": 200
"transfer_rate": 10000
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
},
"is_multi_fluid": false,
"texture": "enderio:block/conduit/fluid",
"transfer_rate": 50
"transfer_rate": 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
},
"is_multi_fluid": false,
"texture": "enderio:block/conduit/pressurized_fluid",
"transfer_rate": 100
"transfer_rate": 1000
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import org.joml.Vector2i;

Expand All @@ -36,6 +37,9 @@ public final class FluidConduitScreenExtension implements ConduitScreenExtension
@Override
public List<AbstractWidget> createWidgets(Screen screen, ConduitDataAccessor conduitDataAccessor, UpdateDispatcher updateConduitData,
Supplier<Direction> direction, Vector2i widgetsStart) {
if (conduitDataAccessor.getOrCreateData(ConduitTypes.Data.FLUID.get()).lockedFluid().isSame(Fluids.EMPTY)) {
return List.of();
}
return List.of(
new FluidWidget(widgetsStart.add(0, 20),
() -> conduitDataAccessor.getOrCreateData(ConduitTypes.Data.FLUID.get()).lockedFluid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ public TextureAtlasSprite getParticleIcon() {
return ModelHelper.getMissingTexture();
}

@Override
public TextureAtlasSprite getParticleIcon(ModelData data) {
ConduitBundle conduitBundle = data.get(ConduitBundleBlockEntity.BUNDLE_MODEL_PROPERTY); //TODO temp particle fix
if (conduitBundle == null) {
return ModelHelper.getMissingTexture();
}
return sprite(conduitBundle, conduitBundle.getConduits().getFirst());
}

@Override
public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.client.model.IQuadTransformer;
import net.neoforged.neoforge.client.model.data.ModelData;
Expand All @@ -39,7 +40,7 @@ public List<BakedQuad> createConnectionQuads(Holder<Conduit<?>> conduit, Conduit

FluidConduitData data = node.getData(ConduitTypes.Data.FLUID.get());

if (data != null && data.lockedFluid() != null) {
if (data != null && !data.lockedFluid().isSame(Fluids.EMPTY)) {
return new FluidPaintQuadTransformer(data.lockedFluid())
.process(Minecraft.getInstance().getModelManager().getModel(FLUID_MODEL)
.getQuads(Blocks.COBBLESTONE.defaultBlockState(), facing, rand, ModelData.EMPTY, type));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.enderio.conduits.client.particle;

import com.enderio.conduits.api.Conduit;
import com.enderio.conduits.common.conduit.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, Conduit<?> conduit) {
Level level = Minecraft.getInstance().level;
ParticleEngine engine = Minecraft.getInstance().particleEngine;
List<AABB> 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, conduit.texture()));
}
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault

package com.enderio.conduits.client.particle;
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.enderio.conduits.api.Conduit;
import com.enderio.base.common.init.EIOCreativeTabs;
import com.enderio.conduits.EnderIOConduits;
import com.enderio.conduits.common.conduit.block.ConduitBundleBlockEntity;
import com.enderio.conduits.common.init.ConduitBlocks;
import com.enderio.conduits.common.init.ConduitComponents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
Expand All @@ -18,7 +20,9 @@
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.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
Expand Down Expand Up @@ -67,15 +71,28 @@ public InteractionResult place(BlockPlaceContext context) {
ItemStack itemstack = context.getItemInHand();

Holder<Conduit<?>> conduit = itemstack.get(ConduitComponents.CONDUIT);
if (conduit == null) {
return InteractionResult.FAIL;
}

// Pass through to existing block.
BlockState blockState = level.getBlockState(blockpos);
if (!blockState.isAir()) {
//noinspection DataFlowIssue
return level.getBlockState(blockpos).useItemOn(context.getItemInHand(), level, player, context.getHand(), context.getHitResult()).result();
// Handle placing into an existing block
if (conduit != null && level.getBlockEntity(blockpos) instanceof ConduitBundleBlockEntity blockEntity) {
if (blockEntity.hasType(conduit)) {
// Pass through to block
return level.getBlockState(blockpos).useWithoutItem(level, player, context.getHitResult());
}

blockEntity.addType(conduit, player);
if (level.isClientSide()) {
blockEntity.updateClient();
}

BlockState blockState = level.getBlockState(blockpos);
SoundType soundtype = blockState.getSoundType(level, blockpos, context.getPlayer());
level.playSound(player, blockpos, this.getPlaceSound(blockState, level, blockpos, context.getPlayer()), SoundSource.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
level.gameEvent(GameEvent.BLOCK_PLACE, blockpos, GameEvent.Context.of(player, blockState));

if (!player.getAbilities().instabuild) {
itemstack.shrink(1);
}
return InteractionResult.sidedSuccess(level.isClientSide());
}

return super.place(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ public RightClickAction addConduit(Level level, Holder<Conduit<?>> conduit, Play
conduits.set(index, conduit);

ConduitGraphObject prevNode = conduitNodes.remove(first.get());
conduitNodes.put(conduit, node);

if (prevNode != null) {
node = new ConduitGraphObject(pos, prevNode.conduitDataContainer()); //new node with old data
conduit.value().onRemoved(prevNode, level, pos);
if (!level.isClientSide() && prevNode.getGraph() != null) {
prevNode.getGraph().remove(prevNode);
}
}

conduitNodes.put(conduit, node);
conduit.value().onCreated(node, level, pos, player);
connections.values().forEach(connection -> connection.disconnectType(index));
onChanged();

return new RightClickAction.Upgrade(first.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public Graph<ConduitGraphContext> getGraph() {
}

@Override
public void setGraph(Graph<ConduitGraphContext> graph) {
public void setGraph(@Nullable Graph<ConduitGraphContext> graph) {
this.graph = graph;
this.wrappedGraph = new WrappedConduitNetwork(graph);
this.wrappedGraph = graph == null ? null: new WrappedConduitNetwork(graph);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ConduitShape {
private final Map<Holder<Conduit<?>>, VoxelShape> conduitShapes = new HashMap<>();
private final Map<Direction, VoxelShape> 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.enderio.conduits.common.conduit.block;

import com.enderio.conduits.api.Conduit;
import com.enderio.base.api.integration.IntegrationManager;
import com.enderio.base.common.init.EIOCapabilities;
import com.enderio.base.common.tag.EIOTags;
import com.enderio.conduits.EnderIOConduits;
import com.enderio.conduits.api.Conduit;
import com.enderio.conduits.common.conduit.ConduitBlockItem;
import com.enderio.conduits.common.conduit.ConduitBundle;
import com.enderio.conduits.common.conduit.ConduitGraphObject;
Expand Down Expand Up @@ -482,12 +482,13 @@ 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 (blockEntity.removeType(conduit, !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;
}
Expand Down Expand Up @@ -567,4 +568,9 @@ private int getSignalOutput(DynamicConnectionState connectionState, RedstoneCond
// endregion

private record OpenInformation(Direction direction, Holder<Conduit<?>> conduit) {}

@Override
protected void spawnDestroyParticles(Level level, Player player, BlockPos pos, BlockState state) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.enderio.conduits.api.upgrade.ConduitUpgrade;
import com.enderio.base.common.init.EIOCapabilities;
import com.enderio.conduits.ConduitNBTKeys;
import com.enderio.conduits.client.particle.ConduitBreakParticle;
import com.enderio.conduits.common.conduit.ConduitBlockItem;
import com.enderio.conduits.common.conduit.ConduitBundle;
import com.enderio.conduits.common.conduit.ConduitDataContainer;
Expand Down Expand Up @@ -367,8 +368,14 @@ public Optional<GraphObject<ConduitGraphContext>> tryConnectTo(Direction dir, Ho

return Optional.of(adjacentBundle.getNodeFor(conduit));
} else if (conduit.value().canConnectTo(level, getBlockPos(), dir)) {
if (bundle.getConnectionState(dir, conduit) instanceof DynamicConnectionState) { //Already connected
onConnectionsUpdated(conduit);
return Optional.empty();
}
connectEnd(dir, conduit);
onConnectionsUpdated(conduit);
} else {
this.disconnect(dir, conduit);
}

return Optional.empty();
Expand Down Expand Up @@ -416,6 +423,11 @@ public boolean removeType(Holder<Conduit<?>> conduit, boolean shouldDrop) {
boolean shouldRemove = bundle.removeConduit(level, conduit);
removeNeighborConnections(conduit);
updateShape();

if (level.isClientSide) {
ConduitBreakParticle.addDestroyEffects(getBlockPos(), conduit.value());
}

return shouldRemove;
}

Expand Down
Loading