ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/tile/TileEntityGiantChest.java

80 lines
2.8 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.common.tile;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.common.util.AwfulUtil;
2016-06-27 20:19:04 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.loot.ILootContainer;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTable;
2019-05-02 09:10:29 +02:00
public class TileEntityGiantChest extends TileEntityInventoryBase implements IButtonReactor, ILootContainer {
public ResourceLocation lootTable;
2016-06-27 20:19:04 +02:00
2019-05-02 09:10:29 +02:00
public TileEntityGiantChest(int slotAmount, String name) {
super(slotAmount, name);
2016-06-27 20:19:04 +02:00
}
2019-05-02 09:10:29 +02:00
public TileEntityGiantChest() {
this(9 * 13, "giantChest");
}
@Override
2019-05-02 09:10:29 +02:00
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
super.writeSyncableNBT(compound, type);
2019-05-02 09:10:29 +02:00
if (this.lootTable != null) {
compound.setString("LootTable", this.lootTable.toString());
}
}
@Override
2019-05-02 09:10:29 +02:00
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
super.readSyncableNBT(compound, type);
2019-05-02 09:10:29 +02:00
if (compound.hasKey("LootTable")) {
this.lootTable = new ResourceLocation(compound.getString("LootTable"));
}
}
2016-06-27 20:19:04 +02:00
@Override
2019-05-02 09:10:29 +02:00
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (player != null && this.pos != null) {
GuiHandler.GuiTypes type;
2016-06-27 20:19:04 +02:00
2019-05-02 09:10:29 +02:00
if (buttonID == 0) {
type = GuiHandler.GuiTypes.GIANT_CHEST;
2019-05-02 09:10:29 +02:00
} else if (buttonID == 1) {
type = GuiHandler.GuiTypes.GIANT_CHEST_PAGE_2;
2019-05-02 09:10:29 +02:00
} else {
type = GuiHandler.GuiTypes.GIANT_CHEST_PAGE_3;
}
2016-06-27 20:19:04 +02:00
2018-05-10 11:38:58 +02:00
player.openGui(ActuallyAdditions.INSTANCE, type.ordinal(), this.world, this.pos.getX(), this.pos.getY(), this.pos.getZ());
}
2016-06-27 20:19:04 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public ResourceLocation getLootTable() {
return this.lootTable;
}
2019-05-02 09:10:29 +02:00
public void fillWithLoot(EntityPlayer player) {
if (this.lootTable != null && !this.world.isRemote && this.world instanceof WorldServer) {
2016-11-26 21:32:27 +01:00
LootTable table = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable);
this.lootTable = null;
2019-05-02 09:10:29 +02:00
LootContext.Builder builder = new LootContext.Builder((WorldServer) this.world);
if (player != null) {
builder.withLuck(player.getLuck());
}
2019-02-27 19:53:05 +01:00
AwfulUtil.fillInventory(table, this.inv, this.world.rand, builder.build());
}
}
}