/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.world.entity.vehicle; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.Container; import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.SlotAccess; 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.entity.vehicle.ContainerEntity; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.phys.Vec3; import org.jspecify.annotations.Nullable; public abstract class AbstractMinecartContainer extends AbstractMinecart implements ContainerEntity { private NonNullList itemStacks = NonNullList.withSize(36, ItemStack.EMPTY); private @Nullable ResourceKey lootTable; private long lootTableSeed; protected AbstractMinecartContainer(EntityType type, Level level) { super(type, level); } @Override public void destroy(ServerLevel level, DamageSource source) { super.destroy(level, source); this.chestVehicleDestroyed(source, level, this); } @Override public ItemStack getItem(int slot) { return this.getChestVehicleItem(slot); } @Override public ItemStack removeItem(int slot, int count) { return this.removeChestVehicleItem(slot, count); } @Override public ItemStack removeItemNoUpdate(int slot) { return this.removeChestVehicleItemNoUpdate(slot); } @Override public void setItem(int slot, ItemStack itemStack) { this.setChestVehicleItem(slot, itemStack); } @Override public SlotAccess getSlot(int slot) { return this.getChestVehicleSlot(slot); } @Override public void setChanged() { } @Override public boolean stillValid(Player player) { return this.isChestVehicleStillValid(player); } @Override public void remove(Entity.RemovalReason reason) { if (!this.level().isClientSide() && reason.shouldDestroy()) { Containers.dropContents(this.level(), this, (Container)this); } super.remove(reason); } @Override protected void addAdditionalSaveData(ValueOutput output) { super.addAdditionalSaveData(output); this.addChestVehicleSaveData(output); } @Override protected void readAdditionalSaveData(ValueInput input) { super.readAdditionalSaveData(input); this.readChestVehicleSaveData(input); } @Override public InteractionResult interact(Player player, InteractionHand hand) { return this.interactWithContainerVehicle(player); } @Override protected Vec3 applyNaturalSlowdown(Vec3 deltaMovement) { float keep = 0.98f; if (this.lootTable == null) { int emptiness = 15 - AbstractContainerMenu.getRedstoneSignalFromContainer(this); keep += (float)emptiness * 0.001f; } if (this.isInWater()) { keep *= 0.95f; } return deltaMovement.multiply(keep, 0.0, keep); } @Override public void clearContent() { this.clearChestVehicleContent(); } public void setLootTable(ResourceKey lootTable, long seed) { this.lootTable = lootTable; this.lootTableSeed = seed; } @Override public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) { if (this.lootTable == null || !player.isSpectator()) { this.unpackChestVehicleLootTable(inventory.player); return this.createMenu(containerId, inventory); } return null; } protected abstract AbstractContainerMenu createMenu(int var1, Inventory var2); @Override public @Nullable ResourceKey getContainerLootTable() { return this.lootTable; } @Override public void setContainerLootTable(@Nullable ResourceKey lootTable) { this.lootTable = lootTable; } @Override public long getContainerLootTableSeed() { return this.lootTableSeed; } @Override public void setContainerLootTableSeed(long lootTableSeed) { this.lootTableSeed = lootTableSeed; } @Override public NonNullList getItemStacks() { return this.itemStacks; } @Override public void clearItemStacks() { this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); } }