Files
CustomNPC-Plus/src/main/java/noppes/npcs/blocks/BlockBorder.java
T

98 lines
3.0 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.blocks.tiles.TileBorder;
import noppes.npcs.constants.EnumGuiType;
2025-03-12 20:12:01 -04:00
public class BlockBorder extends BlockContainer {
public int renderId = -1;
2018-09-13 12:03:28 -04:00
2025-03-12 20:12:01 -04:00
public BlockBorder() {
super(Material.rock);
setBlockUnbreakable();
}
2018-09-13 12:03:28 -04:00
2025-03-12 20:12:01 -04:00
@Override
2018-09-13 12:03:28 -04:00
@SideOnly(Side.CLIENT)
2025-03-12 20:12:01 -04:00
public IIcon getIcon(int side, int meta) {
if (side == 1) {
return this.blockIcon;
}
return Blocks.iron_block.getIcon(side, meta);
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9) {
ItemStack currentItem = player.inventory.getCurrentItem();
if (currentItem != null && currentItem.getItem() == CustomItems.wand) {
CustomNpcs.proxy.openGui(i, j, k, EnumGuiType.Border, player);
return true;
}
return false;
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
@Override
public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
int l = MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
2018-09-13 12:03:28 -04:00
l %= 4;
TileBorder tile = (TileBorder) par1World.getTileEntity(x, y, z);
2025-03-12 20:12:01 -04:00
TileBorder adjacent = getTile(par1World, x - 1, y, z);
if (adjacent == null)
adjacent = getTile(par1World, x, y, z - 1);
if (adjacent == null)
adjacent = getTile(par1World, x, y, z + 1);
if (adjacent == null)
adjacent = getTile(par1World, x + 1, y, z);
if (adjacent != null) {
NBTTagCompound compound = new NBTTagCompound();
adjacent.writeExtraNBT(compound);
tile.readExtraNBT(compound);
}
tile.rotation = l;
}
private TileBorder getTile(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null && tile instanceof TileBorder)
return (TileBorder) tile;
return null;
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
@Override
public int getRenderType() {
return renderId;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileBorder();
2018-09-13 12:03:28 -04:00
}
}