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;
|
2015-02-20 22:45:33 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
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
|
|
|
|
2016-11-20 13:22:36 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class TileEntityGiantChest extends TileEntityInventoryBase implements IButtonReactor, ILootContainer{
|
|
|
|
|
|
|
|
public ResourceLocation lootTable;
|
2016-06-27 20:19:04 +02:00
|
|
|
|
2016-07-03 21:57:33 +02:00
|
|
|
public TileEntityGiantChest(int slotAmount, String name){
|
|
|
|
super(slotAmount, name);
|
2016-06-27 20:19:04 +02:00
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
|
|
|
|
public TileEntityGiantChest(){
|
2016-07-03 21:57:33 +02:00
|
|
|
this(9*13, "giantChest");
|
2015-02-20 22:45:33 +01:00
|
|
|
}
|
|
|
|
|
2016-11-20 13:22:36 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
|
|
|
|
if(this.lootTable != null){
|
|
|
|
compound.setString("LootTable", this.lootTable.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
|
|
|
|
if(compound.hasKey("LootTable")){
|
|
|
|
this.lootTable = new ResourceLocation(compound.getString("LootTable"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2015-10-03 10:19:40 +02:00
|
|
|
return true;
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-04 00:10:52 +01:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack){
|
2015-03-07 02:23:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-27 20:19:04 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonPressed(int buttonID, EntityPlayer player){
|
2016-07-24 12:48:35 +02:00
|
|
|
if(player != null && this.pos != null){
|
|
|
|
GuiHandler.GuiTypes type;
|
2016-06-27 20:19:04 +02:00
|
|
|
|
2016-07-24 12:48:35 +02:00
|
|
|
if(buttonID == 0){
|
|
|
|
type = GuiHandler.GuiTypes.GIANT_CHEST;
|
|
|
|
}
|
|
|
|
else if(buttonID == 1){
|
|
|
|
type = GuiHandler.GuiTypes.GIANT_CHEST_PAGE_2;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
type = GuiHandler.GuiTypes.GIANT_CHEST_PAGE_3;
|
|
|
|
}
|
2016-06-27 20:19:04 +02:00
|
|
|
|
2016-11-26 21:32:27 +01: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
|
|
|
|
public ResourceLocation getLootTable(){
|
|
|
|
return this.lootTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fillWithLoot(EntityPlayer player){
|
2016-11-26 21:32:27 +01:00
|
|
|
if(this.lootTable != null && !this.world.isRemote && this.world instanceof WorldServer){
|
|
|
|
LootTable table = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable);
|
2016-11-20 13:22:36 +01:00
|
|
|
this.lootTable = null;
|
|
|
|
|
2016-11-26 21:32:27 +01:00
|
|
|
LootContext.Builder builder = new LootContext.Builder((WorldServer)this.world);
|
2016-11-20 13:22:36 +01:00
|
|
|
if(player != null){
|
|
|
|
builder.withLuck(player.getLuck());
|
|
|
|
}
|
2016-12-04 00:10:52 +01:00
|
|
|
AwfulUtil.fillInventory(table, this.slots, new Random(), builder.build());
|
2016-11-20 13:22:36 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
}
|