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

bring over #797 #814

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.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<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, ConduitType.getKey(conduit)));
}
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.conduits.client.particle;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ConduitShape {
private final Map<ConduitType<?>, 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
Expand Up @@ -107,17 +107,17 @@ public <T extends ConduitData<T>> RightClickAction addType(Level level, ConduitT
types.set(index, type);

var prevNode = (ConduitGraphObject<T>) 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public Graph<Mergeable.Dummy> getGraph() {
}

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

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -500,4 +503,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) {

}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -305,8 +306,14 @@ public <T extends ConduitData<T>> Optional<GraphObject<Mergeable.Dummy>> 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();
Expand Down Expand Up @@ -348,6 +355,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public static ConduitType<?> getById(int id) {
CONDUIT_TYPES.register("redstone_conduit", RedstoneConduitType::new);

public static final RegistryObject<FluidConduitType> FLUID =
fluidConduit("fluid_conduit", 50, false);
fluidConduit("fluid_conduit", 100, false);

public static final RegistryObject<FluidConduitType> FLUID2 =
fluidConduit("pressurized_fluid_conduit", 100, false);
fluidConduit("pressurized_fluid_conduit", 1_000, false);

public static final RegistryObject<FluidConduitType> FLUID3 =
fluidConduit("ender_fluid_conduit", 200, true);
fluidConduit("ender_fluid_conduit", 10_000, true);

public static final RegistryObject<ItemConduitType> ITEM =
CONDUIT_TYPES.register("item_conduit", ItemConduitType::new);
Expand Down