Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
made plastic bin save max limit to nbt
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Jun 9, 2024
1 parent fac1c2d commit 3f6ff2f
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BlockEntityPlasticBin extends BlockEntityMassStorage {
Expand All @@ -39,6 +41,7 @@ public InteractionResult onInteractServer(BlockState state, Level world, BlockPo
}
//TODO: translation component
player.sendMessage(Utils.literal("Max capacity set to: " + maxLimit), player.getUUID());
this.sidedSync(true);
Utils.damageStack(player.getItemInHand(hand), hand, player);
var handler = itemHandler.map(i -> i.getHandler(SlotTypes.UNLIMITED)).orElse(null);
int amountToExtract = handler.getItem(0).getCount() - maxLimit;
Expand Down Expand Up @@ -68,4 +71,23 @@ public InteractionResult onInteractServer(BlockState state, Level world, BlockPo
}
return super.onInteractServer(state, world, pos, player, hand, hit, type);
}

@Override
public @NotNull CompoundTag getUpdateTag() {
CompoundTag updateTag = super.getUpdateTag();
updateTag.putInt("maxLimit", maxLimit);
return updateTag;
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
maxLimit = tag.getInt("maxLimit");
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
tag.putInt("maxLimit", maxLimit);
}
}

0 comments on commit 3f6ff2f

Please sign in to comment.