mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
183 lines
5.0 KiB
Java
183 lines
5.0 KiB
Java
package com.hbm.blocks.generic;
|
|
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
import com.hbm.inventory.gui.GUIScreenSnowglobe;
|
|
import com.hbm.main.MainRegistry;
|
|
import com.hbm.tileentity.IGUIProvider;
|
|
|
|
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockContainer;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.network.NetworkManager;
|
|
import net.minecraft.network.Packet;
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BlockSnowglobe extends BlockContainer implements IGUIProvider {
|
|
|
|
public BlockSnowglobe() {
|
|
super(Material.glass);
|
|
}
|
|
|
|
@Override
|
|
public int getRenderType() {
|
|
return -1;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOpaqueCube() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean renderAsNormalBlock() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Item getItemDropped(int i, Random rand, int j) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
|
|
|
|
TileEntitySnowglobe entity = (TileEntitySnowglobe) world.getTileEntity(x, y, z);
|
|
|
|
if(entity != null) {
|
|
return new ItemStack(this, 1, entity.type.ordinal());
|
|
}
|
|
|
|
return super.getPickBlock(target, world, x, y, z, player);
|
|
}
|
|
|
|
@Override
|
|
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
|
|
|
if(!world.isRemote) {
|
|
TileEntitySnowglobe entity = (TileEntitySnowglobe) world.getTileEntity(x, y, z);
|
|
if(entity != null) {
|
|
EntityItem item = new EntityItem(world, x + 0.5, y, z + 0.5, new ItemStack(this, 1, entity.type.ordinal()));
|
|
item.motionX = 0;
|
|
item.motionY = 0;
|
|
item.motionZ = 0;
|
|
world.spawnEntityInWorld(item);
|
|
}
|
|
}
|
|
|
|
super.breakBlock(world, x, y, z, block, meta);
|
|
}
|
|
|
|
@Override
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
|
|
|
if(world.isRemote) {
|
|
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
|
|
return true;
|
|
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
|
|
|
|
for(int i = 1; i < SnowglobeType.values().length; i++)
|
|
list.add(new ItemStack(item, 1, i));
|
|
}
|
|
|
|
@Override
|
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
|
int meta = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
|
|
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
|
|
|
|
TileEntitySnowglobe bobble = (TileEntitySnowglobe) world.getTileEntity(x, y, z);
|
|
bobble.type = SnowglobeType.values()[Math.abs(stack.getItemDamage()) % SnowglobeType.values().length];
|
|
bobble.markDirty();
|
|
}
|
|
|
|
@Override
|
|
public TileEntity createNewTileEntity(World world, int meta) {
|
|
return new TileEntitySnowglobe();
|
|
}
|
|
|
|
public static class TileEntitySnowglobe extends TileEntity {
|
|
|
|
public SnowglobeType type = SnowglobeType.NONE;
|
|
|
|
@Override
|
|
public boolean canUpdate() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Packet getDescriptionPacket() {
|
|
NBTTagCompound nbt = new NBTTagCompound();
|
|
this.writeToNBT(nbt);
|
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt);
|
|
}
|
|
|
|
@Override
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
|
this.readFromNBT(pkt.func_148857_g());
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
super.readFromNBT(nbt);
|
|
this.type = SnowglobeType.values()[Math.abs(nbt.getByte("type")) % SnowglobeType.values().length];
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
super.writeToNBT(nbt);
|
|
nbt.setByte("type", (byte) type.ordinal());
|
|
}
|
|
}
|
|
|
|
public static enum SnowglobeType {
|
|
NONE( "NONE"),
|
|
RIVETCITY( "Rivet City"),
|
|
TENPENNYTOWER( "Tenpenny Tower"),
|
|
LUCKY38( "Lucky 38"),
|
|
SIERRAMADRE( "Sierra Madre"),
|
|
PRYDWEN( "Prydwen");
|
|
|
|
public String label;
|
|
|
|
private SnowglobeType(String label) {
|
|
this.label = label;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
return new GUIScreenSnowglobe((TileEntitySnowglobe) world.getTileEntity(x, y, z));
|
|
}
|
|
}
|