ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/blocks/BlockGiantChest.java

151 lines
5.6 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("BlockGiantChest.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-12-30 22:02:15 +01:00
package de.ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-12-30 22:02:15 +01:00
import de.ellpeck.actuallyadditions.ActuallyAdditions;
import de.ellpeck.actuallyadditions.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.items.InitItems;
import de.ellpeck.actuallyadditions.tile.TileEntityGiantChest;
import de.ellpeck.actuallyadditions.util.ItemUtil;
import de.ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
2015-12-16 15:22:19 +01:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
2015-12-16 15:22:19 +01:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
2015-12-16 15:22:19 +01:00
import java.util.ArrayList;
public class BlockGiantChest extends BlockContainerBase{
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
private IIcon topIcon;
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
private IIcon bottomIcon;
public BlockGiantChest(String name){
super(Material.wood, name);
this.setHarvestLevel("axe", 0);
this.setHardness(0.5F);
this.setResistance(15.0F);
this.setStepSound(soundTypeWood);
}
@Override
public TileEntity createNewTileEntity(World world, int par2){
return new TileEntityGiantChest();
}
@Override
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata){
return side == 1 ? this.topIcon : (side == 0 ? this.bottomIcon : this.blockIcon);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
if(!world.isRemote){
TileEntityGiantChest chest = (TileEntityGiantChest)world.getTileEntity(x, y, z);
2015-10-02 16:48:01 +02:00
if(chest != null){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.GIANT_CHEST.ordinal(), world, x, y, z);
}
return true;
}
return true;
}
@Override
2015-10-03 10:19:40 +02:00
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconReg){
this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName());
this.topIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()+"Top");
this.bottomIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()+"Bottom");
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.epic;
}
2015-12-21 22:46:23 +01:00
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack){
if(stack.getTagCompound() != null){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityGiantChest){
NBTTagList list = stack.getTagCompound().getTagList("Items", 10);
ItemStack[] slots = ((TileEntityGiantChest)tile).slots;
for(int i = 0; i < list.tagCount(); i++){
slots[i] = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(i));
}
}
}
super.onBlockPlacedBy(world, x, y, z, entity, stack);
}
2015-12-16 15:22:19 +01:00
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){
ArrayList<ItemStack> drops = super.getDrops(world, x, y, z, metadata, fortune);
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityGiantChest){
ItemStack[] slots = ((TileEntityGiantChest)tile).slots;
int place = ItemUtil.getPlaceAt(slots, new ItemStack(InitItems.itemCrateKeeper), false);
if(place >= 0){
NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++){
//Destroy the keeper
if(i != place){
if(slots[i] != null){
list.appendTag(slots[i].writeToNBT(new NBTTagCompound()));
}
}
}
if(list.tagCount() > 0){
ItemStack stackInQuestion = drops.get(0);
if(stackInQuestion != null){
if(stackInQuestion.getTagCompound() == null){
stackInQuestion.setTagCompound(new NBTTagCompound());
}
stackInQuestion.getTagCompound().setTag("Items", list);
}
}
}
}
return drops;
}
2015-12-19 10:30:39 +01:00
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityGiantChest){
if(!ItemUtil.contains(((TileEntityGiantChest)tile).slots, new ItemStack(InitItems.itemCrateKeeper), false)){
this.dropInventory(world, x, y, z);
}
}
super.breakBlock(world, x, y, z, block, par6);
}
}