Skip to content

Commit

Permalink
Merge pull request #218 from MuradAkh/fix-issue-216-1.19
Browse files Browse the repository at this point in the history
Fix duplication glitch
  • Loading branch information
EDToaster authored Dec 26, 2022
2 parents 8ee957c + 5723b2b commit 97f4f8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import dev.murad.shipping.setup.ModEntityTypes;
import dev.murad.shipping.setup.ModItems;
import dev.murad.shipping.util.FluidDisplayUtil;
import dev.murad.shipping.util.ItemHandlerVanillaContainerWrapper;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.*;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
Expand All @@ -28,7 +25,6 @@

public class ChestCarEntity extends AbstractWagonEntity implements ItemHandlerVanillaContainerWrapper, WorldlyContainer, MenuProvider {
protected final ItemStackHandler itemHandler = createHandler();

protected final LazyOptional<IItemHandler> handler = LazyOptional.of(() -> itemHandler);
public ChestCarEntity(EntityType<ChestCarEntity> p_38087_, Level p_38088_) {
super(p_38087_, p_38088_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public void remove(RemovalReason r) {
super.remove(r);
}



@Override
public Item getDropItem() {
return ModItems.CHEST_BARGE.get();
Expand Down Expand Up @@ -71,32 +69,31 @@ public boolean isEmpty() {
}

@Override
public ItemStack getItem(int p_70301_1_) {
return this.itemStacks.get(p_70301_1_);
public ItemStack getItem(int slot) {
return this.itemStacks.get(slot);
}

@Override
public ItemStack removeItem(int p_70298_1_, int p_70298_2_) {
return ContainerHelper.removeItem(this.itemStacks, p_70298_1_, p_70298_2_);

public ItemStack removeItem(int slot, int count) {
return ContainerHelper.removeItem(this.itemStacks, slot, count);
}

@Override
public ItemStack removeItemNoUpdate(int p_70304_1_) {
ItemStack itemstack = this.itemStacks.get(p_70304_1_);
public ItemStack removeItemNoUpdate(int slot) {
ItemStack itemstack = this.itemStacks.get(slot);
if (itemstack.isEmpty()) {
return ItemStack.EMPTY;
} else {
this.itemStacks.set(p_70304_1_, ItemStack.EMPTY);
this.itemStacks.set(slot, ItemStack.EMPTY);
return itemstack;
}
}

@Override
public void setItem(int p_70299_1_, ItemStack p_70299_2_) {
this.itemStacks.set(p_70299_1_, p_70299_2_);
if (!p_70299_2_.isEmpty() && p_70299_2_.getCount() > this.getMaxStackSize()) {
p_70299_2_.setCount(this.getMaxStackSize());
public void setItem(int slot, ItemStack stack) {
this.itemStacks.set(slot, stack);
if (!stack.isEmpty() && stack.getCount() > this.getMaxStackSize()) {
stack.setCount(this.getMaxStackSize());
}
}

Expand All @@ -106,11 +103,11 @@ public void setChanged() {
}

@Override
public boolean stillValid(Player p_70300_1_) {
public boolean stillValid(Player player) {
if (this.isRemoved()) {
return false;
} else {
return !(p_70300_1_.distanceToSqr(this) > 64.0D);
return !(player.distanceToSqr(this) > 64.0D);
}
}

Expand All @@ -129,20 +126,19 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory,
}

@Override
public void addAdditionalSaveData(CompoundTag p_213281_1_) {
super.addAdditionalSaveData(p_213281_1_);
ContainerHelper.saveAllItems(p_213281_1_, this.itemStacks);

public void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
ContainerHelper.saveAllItems(tag, this.itemStacks);
}

@Override
public void readAdditionalSaveData(CompoundTag p_70037_1_) {
super.readAdditionalSaveData(p_70037_1_);
ContainerHelper.loadAllItems(p_70037_1_, this.itemStacks);
public void readAdditionalSaveData(CompoundTag tag) {
super.readAdditionalSaveData(tag);
ContainerHelper.loadAllItems(tag, this.itemStacks);
}

@Override
public int[] getSlotsForFace(Direction p_180463_1_) {
public int[] getSlotsForFace(Direction face) {
return IntStream.range(0, getContainerSize()).toArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ default boolean isEmpty() {
}

default ItemStack getItem(int pIndex) {
return getRawHandler().getStackInSlot(pIndex);
return getRawHandler().getStackInSlot(pIndex);
}

default ItemStack removeItem(int pIndex, int pCount) {
return getRawHandler().extractItem(pIndex, pCount, false);
}

default ItemStack removeItemNoUpdate(int pIndex) {
var stack = getRawHandler().getStackInSlot(pIndex);
getRawHandler().setStackInSlot(pIndex, ItemStack.EMPTY);
var stack = getRawHandler().getStackInSlot(pIndex);
getRawHandler().setStackInSlot(pIndex, ItemStack.EMPTY);
return stack;
}

default void setItem(int pIndex, ItemStack pStack) {
getRawHandler().insertItem(pIndex, pStack, false);
getRawHandler().setStackInSlot(pIndex, pStack);
}

default void setChanged() {
Expand Down

0 comments on commit 97f4f8f

Please sign in to comment.