168 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			168 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| 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.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.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.jetbrains.annotations.Nullable;
 | |
| 
 | |
| public abstract class AbstractMinecartContainer extends AbstractMinecart implements ContainerEntity {
 | |
| 	private NonNullList<ItemStack> itemStacks = NonNullList.withSize(36, ItemStack.EMPTY);
 | |
| 	@Nullable
 | |
| 	private ResourceKey<LootTable> lootTable;
 | |
| 	private long lootTableSeed;
 | |
| 
 | |
| 	protected AbstractMinecartContainer(EntityType<?> entityType, Level level) {
 | |
| 		super(entityType, level);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void destroy(ServerLevel level, DamageSource damageSource) {
 | |
| 		super.destroy(level, damageSource);
 | |
| 		this.chestVehicleDestroyed(damageSource, level, this);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public ItemStack getItem(int slot) {
 | |
| 		return this.getChestVehicleItem(slot);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public ItemStack removeItem(int slot, int amount) {
 | |
| 		return this.removeChestVehicleItem(slot, amount);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public ItemStack removeItemNoUpdate(int slot) {
 | |
| 		return this.removeChestVehicleItemNoUpdate(slot);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void setItem(int slot, ItemStack stack) {
 | |
| 		this.setChestVehicleItem(slot, stack);
 | |
| 	}
 | |
| 
 | |
| 	@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, 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 speed) {
 | |
| 		float f = 0.98F;
 | |
| 		if (this.lootTable == null) {
 | |
| 			int i = 15 - AbstractContainerMenu.getRedstoneSignalFromContainer(this);
 | |
| 			f += i * 0.001F;
 | |
| 		}
 | |
| 
 | |
| 		if (this.isInWater()) {
 | |
| 			f *= 0.95F;
 | |
| 		}
 | |
| 
 | |
| 		return speed.multiply(f, 0.0, f);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void clearContent() {
 | |
| 		this.clearChestVehicleContent();
 | |
| 	}
 | |
| 
 | |
| 	public void setLootTable(ResourceKey<LootTable> lootTable, long seed) {
 | |
| 		this.lootTable = lootTable;
 | |
| 		this.lootTableSeed = seed;
 | |
| 	}
 | |
| 
 | |
| 	@Nullable
 | |
| 	@Override
 | |
| 	public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
 | |
| 		if (this.lootTable != null && player.isSpectator()) {
 | |
| 			return null;
 | |
| 		} else {
 | |
| 			this.unpackChestVehicleLootTable(inventory.player);
 | |
| 			return this.createMenu(i, inventory);
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	protected abstract AbstractContainerMenu createMenu(int containerId, Inventory playerInventory);
 | |
| 
 | |
| 	@Nullable
 | |
| 	@Override
 | |
| 	public ResourceKey<LootTable> getContainerLootTable() {
 | |
| 		return this.lootTable;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void setContainerLootTable(@Nullable ResourceKey<LootTable> lootTable) {
 | |
| 		this.lootTable = lootTable;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public long getContainerLootTableSeed() {
 | |
| 		return this.lootTableSeed;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void setContainerLootTableSeed(long lootTableSeed) {
 | |
| 		this.lootTableSeed = lootTableSeed;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public NonNullList<ItemStack> getItemStacks() {
 | |
| 		return this.itemStacks;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void clearItemStacks() {
 | |
| 		this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
 | |
| 	}
 | |
| }
 |