Skip to content

Commit

Permalink
Fix issues causing bleeding Frequency properties.
Browse files Browse the repository at this point in the history
- Sometimes a container would have a owner name in the corner when it should not have.
  • Loading branch information
covers1624 committed Aug 25, 2022
1 parent 8d25d6c commit 2ab79c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
25 changes: 14 additions & 11 deletions src/main/java/codechicken/enderstorage/api/Frequency.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import codechicken.lib.util.Copyable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

import java.util.UUID;
Expand Down Expand Up @@ -82,13 +83,15 @@ public Frequency setRight(EnumColour right) {
return this;
}

public Frequency setOwner(UUID owner) {
this.owner = owner;
public Frequency setOwner(Player player) {
owner = player.getUUID();
ownerName = player.getName();
return this;
}

public Frequency setOwnerName(Component ownerName) {
this.ownerName = ownerName;
public Frequency clearOwner() {
owner = null;
ownerName = null;
return this;
}

Expand All @@ -104,11 +107,11 @@ public Frequency set(EnumColour[] colours) {
}

public Frequency set(Frequency frequency) {
setLeft(frequency.left);
setMiddle(frequency.middle);
setRight(frequency.right);
setOwner(frequency.owner);
setOwnerName(frequency.ownerName);
left = frequency.left;
middle = frequency.middle;
right = frequency.right;
owner = frequency.owner;
ownerName = frequency.ownerName;
return this;
}

Expand Down Expand Up @@ -136,7 +139,7 @@ public EnumColour[] toArray() {
return new EnumColour[] { left, middle, right };
}

protected Frequency read_internal(CompoundTag tagCompound) {
private Frequency read_internal(CompoundTag tagCompound) {
left = EnumColour.fromWoolMeta(tagCompound.getInt("left"));
middle = EnumColour.fromWoolMeta(tagCompound.getInt("middle"));
right = EnumColour.fromWoolMeta(tagCompound.getInt("right"));
Expand All @@ -149,7 +152,7 @@ protected Frequency read_internal(CompoundTag tagCompound) {
return this;
}

protected CompoundTag write_internal(CompoundTag tagCompound) {
private CompoundTag write_internal(CompoundTag tagCompound) {
tagCompound.putInt("left", left.getWoolMeta());
tagCompound.putInt("middle", middle.getWoolMeta());
tagCompound.putInt("right", right.getWoolMeta());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,11 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
return InteractionResult.FAIL;
}

owner.setFreq(owner.getFrequency().copy().setOwner(null));
owner.setFreq(owner.getFrequency().copy().clearOwner());
return InteractionResult.SUCCESS;
} else if (!item.isEmpty() && ItemUtils.areStacksSameType(item, EnderStorageConfig.getPersonalItem())) {
if (!owner.getFrequency().hasOwner()) {
owner.setFreq(owner.getFrequency().copy()//
.setOwner(player.getUUID())//
.setOwnerName(player.getName())//
);
owner.setFreq(owner.getFrequency().copy().setOwner(player));
if (!player.getAbilities().instabuild) {
item.shrink(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

//@ChestContainer
public class ContainerEnderItemStorage extends AbstractContainerMenu {

public EnderItemStorage chestInv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
}

BlockEntity tile = world.getBlockEntity(context.getClickedPos());
if (tile instanceof TileEnderChest && context.getPlayer().isCrouching()) {
TileEnderChest chest = (TileEnderChest) tile;
if (tile instanceof TileEnderChest chest && context.getPlayer().isCrouching()) {
Frequency frequency = chest.getFrequency().copy();
if (EnderStorageConfig.anarchyMode && !(frequency.owner != null && frequency.owner.equals(context.getPlayer().getUUID()))) {
frequency.setOwner(null);
frequency.clearOwner();
}

frequency.writeToStack(stack);
Expand Down

0 comments on commit 2ab79c6

Please sign in to comment.