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

90 lines
3.1 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityGiantChest.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.tile;
2016-06-27 20:19:04 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.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());
}
}
}