Skip to content

Commit

Permalink
bring over #797
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Oct 1, 2024
1 parent d26fb4c commit 50ee77b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.enderio.conduits.client.particle;

Check failure on line 1 in src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java

View workflow job for this annotation

GitHub Actions / runner / checkstyle

[checkstyle] reported by reviewdog 🐶 Missing package-info.java file. Raw Output: /github/workspace/./src/conduits/java/com/enderio/conduits/client/particle/ConduitBreakParticle.java:1:0: error: Missing package-info.java file. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck)

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
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 @@ -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) {

}
}
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 @@ -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;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ public abstract class VacuumMachineBlockEntity<T extends Entity> extends Machine
protected static final double SPEED_4 = SPEED * 4;
private List<WeakReference<T>> entities = new ArrayList<>();
private Class<T> targetClass;
public static SingleSlotAccess FILTER = new SingleSlotAccess();

protected static final Predicate<ItemEntity> ITEM_ENTITY_FILTER_TRUE = itemEntity -> true;

Expand Down

0 comments on commit 50ee77b

Please sign in to comment.