diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/block/MetaMachineBlock.java b/common/src/main/java/com/gregtechceu/gtceu/api/block/MetaMachineBlock.java index 9ba98c6faa..47589300e6 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/block/MetaMachineBlock.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/block/MetaMachineBlock.java @@ -31,7 +31,6 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; @@ -194,7 +193,7 @@ public List getDrops(BlockState state, LootParams.Builder builder) { if (tileEntity instanceof IMachineBlockEntity holder) { var machine = holder.getMetaMachine(); for (Direction direction : Direction.values()) { - machine.getCoverContainer().removeCover(direction); + machine.getCoverContainer().removeCover(direction, null); } if (machine instanceof IMachineModifyDrops machineModifyDrops && entity instanceof Player) { machineModifyDrops.onDrops(drops, (Player) entity); diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/block/PipeBlock.java b/common/src/main/java/com/gregtechceu/gtceu/api/block/PipeBlock.java index 62d835c589..53fc97bd44 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/block/PipeBlock.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/block/PipeBlock.java @@ -35,8 +35,10 @@ import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.phys.shapes.*; -import org.apache.commons.lang3.ArrayUtils; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.EntityCollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @@ -238,7 +240,7 @@ public List getDrops(BlockState state, LootParams.Builder builder) { BlockEntity tileEntity = context.getParamOrNull(LootContextParams.BLOCK_ENTITY); if (tileEntity instanceof IPipeNode pipeTile) { for (Direction direction : Direction.values()) { - pipeTile.getCoverContainer().removeCover(direction); + pipeTile.getCoverContainer().removeCover(direction, null); } } return super.getDrops(state, builder); diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/blockentity/PipeBlockEntity.java b/common/src/main/java/com/gregtechceu/gtceu/api/blockentity/PipeBlockEntity.java index 031e5ba217..a0ba774229 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/blockentity/PipeBlockEntity.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/blockentity/PipeBlockEntity.java @@ -1,20 +1,20 @@ package com.gregtechceu.gtceu.api.blockentity; import com.gregtechceu.gtceu.api.GTValues; +import com.gregtechceu.gtceu.api.block.BlockProperties; import com.gregtechceu.gtceu.api.block.MaterialPipeBlock; +import com.gregtechceu.gtceu.api.capability.ICoverable; +import com.gregtechceu.gtceu.api.capability.IToolable; import com.gregtechceu.gtceu.api.cover.CoverBehavior; import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.api.pipenet.IPipeNode; -import com.gregtechceu.gtceu.api.pipenet.PipeCoverContainer; -import com.gregtechceu.gtceu.api.block.BlockProperties; -import com.gregtechceu.gtceu.api.capability.ICoverable; -import com.gregtechceu.gtceu.api.capability.IToolable; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.item.tool.IToolGridHighLight; import com.gregtechceu.gtceu.api.machine.TickableSubscription; import com.gregtechceu.gtceu.api.pipenet.IAttachData; +import com.gregtechceu.gtceu.api.pipenet.IPipeNode; import com.gregtechceu.gtceu.api.pipenet.IPipeType; +import com.gregtechceu.gtceu.api.pipenet.PipeCoverContainer; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.syncdata.EnhancedFieldManagedStorage; import com.gregtechceu.gtceu.api.syncdata.IEnhancedManaged; @@ -286,7 +286,7 @@ public InteractionResult onToolClick(@NotNull GTToolType toolType, ItemStack ite } else if (toolType == GTToolType.CROWBAR) { if (coverBehavior != null) { if (!isRemote()) { - getCoverContainer().removeCover(gridSide); + getCoverContainer().removeCover(gridSide, playerIn); } return InteractionResult.CONSUME; } diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java b/common/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java index 5726d0d7a4..2cf8667217 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java @@ -64,7 +64,7 @@ public interface ICoverable extends ITickSubscription, IAppearance, IFancyConfig /** * Its an internal method, you should never call it yourself. *
- * Use {@link ICoverable#removeCover(boolean, Direction)} and {@link ICoverable#placeCoverOnSide(Direction, ItemStack, CoverDefinition, ServerPlayer)} instead + * Use {@link ICoverable#removeCover(boolean, Direction, Player)} and {@link ICoverable#placeCoverOnSide(Direction, ItemStack, CoverDefinition, ServerPlayer)} instead * @param coverBehavior * @param side */ @@ -79,7 +79,7 @@ default boolean placeCoverOnSide(Direction side, ItemStack itemStack, CoverDefin return false; } if (getCoverAtSide(side) != null) { - removeCover(side); + removeCover(side, player); } coverBehavior.onAttached(itemStack, player); coverBehavior.onLoad(); @@ -92,7 +92,7 @@ default boolean placeCoverOnSide(Direction side, ItemStack itemStack, CoverDefin return true; } - default boolean removeCover(boolean dropItself, Direction side) { + default boolean removeCover(boolean dropItself, Direction side, @Nullable Player player) { CoverBehavior coverBehavior = getCoverAtSide(side); if (coverBehavior == null) { return false; @@ -104,7 +104,11 @@ default boolean removeCover(boolean dropItself, Direction side) { coverBehavior.onRemoved(); setCoverAtSide(null, side); for (ItemStack dropStack : drops) { + if (player != null && player.getInventory().add(dropStack)) + continue; + Block.popResource(getLevel(), getPos(), dropStack); + } notifyBlockUpdate(); markDirty(); @@ -112,8 +116,8 @@ default boolean removeCover(boolean dropItself, Direction side) { return true; } - default boolean removeCover(Direction side) { - return removeCover(true, side); + default boolean removeCover(Direction side, @Nullable Player player) { + return removeCover(true, side, player); } default List getCovers() { diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/gui/widget/CoverContainerConfigurator.java b/common/src/main/java/com/gregtechceu/gtceu/api/gui/widget/CoverContainerConfigurator.java index 4adc3e1513..624ccc4da5 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/gui/widget/CoverContainerConfigurator.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/gui/widget/CoverContainerConfigurator.java @@ -25,9 +25,7 @@ import net.minecraft.core.Direction; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.phys.Vec2; import javax.annotation.Nullable; import java.util.List; @@ -105,7 +103,7 @@ private void coverRemoved() { if (getGui().entityPlayer instanceof ServerPlayer serverPlayer && side != null) { var item = transfer.getStackInSlot(0); if (coverable.getCoverAtSide(side) != null) { - coverable.removeCover(false, side); + coverable.removeCover(false, side, serverPlayer); } if (!item.isEmpty() && coverable.getCoverAtSide(side) == null) { if (item.getItem() instanceof ComponentItem componentItem) { diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java b/common/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java index cdad5f44e8..ed7aff90f2 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java @@ -298,7 +298,7 @@ public final InteractionResult onToolClick(@NotNull GTToolType toolType, ItemSta } else if (toolType == GTToolType.CROWBAR) { if (coverBehavior != null) { if (!isRemote()) { - getCoverContainer().removeCover(gridSide); + getCoverContainer().removeCover(gridSide, playerIn); } return InteractionResult.CONSUME; } diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java index f3c18b08be..6ca0771ac7 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java @@ -116,7 +116,7 @@ public FluidStack drainInternal(FluidStack resource, boolean simulate) { @NotNull @Override public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { - if (proxy != null && canCapInput()) { + if (proxy != null && canCapOutput()) { return proxy.drain(maxDrain, simulate, notifyChanges); } return FluidStack.empty(); @@ -125,7 +125,7 @@ public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) @NotNull @Override public FluidStack drain(FluidStack resource, boolean simulate, boolean notifyChanges) { - if (proxy != null && canCapInput()) { + if (proxy != null && canCapOutput()) { return proxy.drain(resource, simulate, notifyChanges); } return FluidStack.empty(); diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index d23f89225d..fcdd0804a9 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -15,7 +15,6 @@ import lombok.Getter; import lombok.Setter; import net.minecraft.core.Direction; -import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -335,7 +334,7 @@ public FluidStack drainInternal(FluidStack resource, boolean simulate) { @NotNull @Override public FluidStack drain(long maxDrain, boolean simulate) { - if (canCapInput()) { + if (canCapOutput()) { return drainInternal(maxDrain, simulate); } return FluidStack.empty(); diff --git a/forge/src/main/java/com/gregtechceu/gtceu/api/blockentity/forge/MetaMachineBlockEntityImpl.java b/forge/src/main/java/com/gregtechceu/gtceu/api/blockentity/forge/MetaMachineBlockEntityImpl.java index 60f726b5ed..abae0b9cda 100644 --- a/forge/src/main/java/com/gregtechceu/gtceu/api/blockentity/forge/MetaMachineBlockEntityImpl.java +++ b/forge/src/main/java/com/gregtechceu/gtceu/api/blockentity/forge/MetaMachineBlockEntityImpl.java @@ -149,11 +149,11 @@ public static LazyOptional getCapability(MetaMachine machine, @NotNull Ca } } else if (cap == GTCapability.CAPABILITY_LASER) { if (machine instanceof ILaserContainer energyContainer) { - return GTCapability.CAPABILITY_ENERGY_CONTAINER.orEmpty(cap, LazyOptional.of(() -> energyContainer)); + return GTCapability.CAPABILITY_LASER.orEmpty(cap, LazyOptional.of(() -> energyContainer)); } var list = machine.getTraits().stream().filter(ILaserContainer.class::isInstance).filter(t -> t.hasCapability(side)).map(ILaserContainer.class::cast).toList(); if (!list.isEmpty()) { - return GTCapability.CAPABILITY_ENERGY_CONTAINER.orEmpty(cap, LazyOptional.of(() -> list.size() == 1 ? list.get(0) : new LaserContainerList(list))); + return GTCapability.CAPABILITY_LASER.orEmpty(cap, LazyOptional.of(() -> list.size() == 1 ? list.get(0) : new LaserContainerList(list))); } }