Skip to content

Commit

Permalink
bring over #797
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Sep 26, 2024
1 parent befdbca commit 341f0f1
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 21 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 @@ -150,7 +150,7 @@ private int ticksForAction() {
}

private boolean hasPowerToCraft() {
return this.energyStorage.consumeEnergy(MachinesConfig.COMMON.ENERGY.CRAFTING_RECIPE_COST.get(), true) > 0;
return this.energyStorage.consumeEnergy(MachinesConfig.COMMON.ENERGY.CRAFTING_RECIPE_COST.get(), true) >= MachinesConfig.COMMON.ENERGY.CRAFTING_RECIPE_COST.get();
}

private void processOutputBuffer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enderio.machines.common.blockentity;

import com.enderio.api.filter.ItemStackFilter;
import com.enderio.base.common.init.EIOCapabilities;
import com.enderio.machines.common.blockentity.base.VacuumMachineBlockEntity;
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.io.item.MachineInventoryLayout;
Expand Down Expand Up @@ -30,8 +32,10 @@ public AbstractContainerMenu createMenu(int containerId, Inventory inventory, Pl
@Override
public MachineInventoryLayout getInventoryLayout() {
return extractableGUISlot(MachineInventoryLayout.builder(), 27)
.slot(slot -> slot.guiInsert().guiExtract().filter((i, s) -> false))
.build(); //TODO add proper filter slot and predicate
.slot(slot -> slot.guiInsert().guiExtract().filter((i, s) -> s.getCapability(EIOCapabilities.FILTER)
.map(f -> f instanceof ItemStackFilter).orElse(false)))
.slotAccess(FILTER)
.build();
}

@Override
Expand All @@ -52,11 +56,12 @@ public String getColor() {
return MachinesConfig.CLIENT.BLOCKS.VACUUM_CHEST_RANGE_COLOR.get();
}

//TODO filter
@Override
public Predicate<ItemEntity> getFilter() {
// get filter slot -> get filter item -> filter
// maybe cache on item insert
var filter = FILTER.getItemStack(this).getCapability(EIOCapabilities.FILTER);
if (filter.resolve().isPresent() && filter.resolve().get() instanceof ItemStackFilter itemStackFilter) {
return itemEntity -> itemStackFilter.test(itemEntity.getItem());
}
return super.getFilter();
}

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.level.Level;
Expand All @@ -26,6 +27,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();

public VacuumMachineBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState, Class<T> targetClass) {
super(pType, pWorldPosition, pBlockState);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,19 @@ public void setInverted(Boolean inverted) {

@Override
public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) {
if (pSlotId < capability.getEntries().size()) {
if (pSlotId < capability.getEntries().size() && pSlotId >= 0) {
if (!capability.getEntries().get(pSlotId).isEmpty()) {
capability.setEntry(pSlotId, FluidStack.EMPTY);
}
}
super.clicked(pSlotId, pButton, pClickType, pPlayer);
}

@Override
public void doClick(int slotId, int button, ClickType clickType, Player player) {
if (clickType == ClickType.PICKUP && slotId < capability.getEntries().size() && slotId >= 0) {
this.getSlot(slotId).set(ItemStack.EMPTY);
}
super.doClick(slotId, button, clickType, player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -95,4 +96,12 @@ public void setInverted(Boolean inverted) {
CoreNetwork.sendToServer(new FilterUpdatePacket(capability.isNbt(), inverted));
capability.setInverted(inverted);
}

@Override
public void doClick(int slotId, int button, ClickType clickType, Player player) {
if (clickType == ClickType.PICKUP && slotId < capability.getEntries().size() && slotId >= 0) {
this.getSlot(slotId).set(ItemStack.EMPTY);
}
super.doClick(slotId, button, clickType, player);
}
}

0 comments on commit 341f0f1

Please sign in to comment.