Skip to content

Commit

Permalink
Fixes (#520)
Browse files Browse the repository at this point in the history
* fix: return correct capability for lasers

* feat: insert covers directly into inventory on crowbar use, if possible

* fix: capability IO directions
  • Loading branch information
mikerooni authored Nov 5, 2023
1 parent b8d51d6 commit 7ead212
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -194,7 +193,7 @@ public List<ItemStack> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -238,7 +240,7 @@ public List<ItemStack> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface ICoverable extends ITickSubscription, IAppearance, IFancyConfig
/**
* Its an internal method, you should never call it yourself.
* <br>
* 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
*/
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -104,16 +104,20 @@ 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();
scheduleNeighborShapeUpdate();
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<CoverBehavior> getCovers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public static <T> LazyOptional<T> 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)));
}

}
Expand Down

0 comments on commit 7ead212

Please sign in to comment.