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;
|
2015-02-20 22:45:33 +01:00
|
|
|
|
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;
|
2016-12-04 00:10:52 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AwfulUtil;
|
2016-06-27 20:19:04 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-11-20 13:22:36 +01:00
|
|
|
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;
|
2015-02-20 22:45:33 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityGiantChest extends TileEntityInventoryBase implements IButtonReactor, ILootContainer {
|
2016-11-20 13:22:36 +01:00
|
|
|
|
|
|
|
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) {
|
2016-07-03 21:57:33 +02:00
|
|
|
super(slotAmount, name);
|
2016-06-27 20:19:04 +02:00
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityGiantChest() {
|
|
|
|
this(9 * 13, "giantChest");
|
2015-02-20 22:45:33 +01:00
|
|
|
}
|
|
|
|
|
2016-11-20 13:22:36 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
2016-11-20 13:22:36 +01:00
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.lootTable != null) {
|
2016-11-20 13:22:36 +01:00
|
|
|
compound.setString("LootTable", this.lootTable.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
2016-11-20 13:22:36 +01:00
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (compound.hasKey("LootTable")) {
|
2016-11-20 13:22:36 +01:00
|
|
|
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) {
|
2016-07-24 12:48:35 +02:00
|
|
|
GuiHandler.GuiTypes type;
|
2016-06-27 20:19:04 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (buttonID == 0) {
|
2016-07-24 12:48:35 +02:00
|
|
|
type = GuiHandler.GuiTypes.GIANT_CHEST;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (buttonID == 1) {
|
2016-07-24 12:48:35 +02:00
|
|
|
type = GuiHandler.GuiTypes.GIANT_CHEST_PAGE_2;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-07-24 12:48:35 +02:00
|
|
|
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-07-24 12:48:35 +02:00
|
|
|
}
|
2016-06-27 20:19:04 +02:00
|
|
|
}
|
2016-11-20 13:22:36 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ResourceLocation getLootTable() {
|
2016-11-20 13:22:36 +01:00
|
|
|
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);
|
2016-11-20 13:22:36 +01:00
|
|
|
this.lootTable = null;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
LootContext.Builder builder = new LootContext.Builder((WorldServer) this.world);
|
|
|
|
if (player != null) {
|
2016-11-20 13:22:36 +01:00
|
|
|
builder.withLuck(player.getLuck());
|
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
AwfulUtil.fillInventory(table, this.inv, this.world.rand, builder.build());
|
2016-11-20 13:22:36 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
}
|