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

110 lines
3.3 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;
2025-02-09 20:49:45 -05:00
import net.minecraft.block.Block;
2018-09-13 12:03:28 -04:00
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
2018-09-13 12:03:28 -04:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
2018-09-13 12:03:28 -04:00
import net.minecraft.util.MathHelper;
2025-02-12 20:35:46 -05:00
import net.minecraft.world.IBlockAccess;
2018-09-13 12:03:28 -04:00
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.blocks.tiles.TileBlockAnvil;
import noppes.npcs.constants.EnumGuiType;
2023-01-12 21:33:06 -05:00
import java.util.List;
2025-03-12 20:12:01 -04:00
public class BlockCarpentryBench extends BlockContainer {
public int renderId = -1;
public BlockCarpentryBench() {
2025-02-12 20:35:46 -05:00
super(Material.rock);
setStepSound(soundTypePiston);
}
@Override
2025-03-12 20:12:01 -04:00
public int getLightValue(IBlockAccess world, int x, int y, int z) {
2025-02-12 20:35:46 -05:00
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
2025-03-12 20:12:01 -04:00
if (block != this) {
2025-02-12 20:35:46 -05:00
return block.getLightValue(world, x, y, z);
}
2025-03-12 20:12:01 -04:00
if (meta >= 4)
2025-02-12 20:35:46 -05:00
return 5;
return getLightValue();
2018-09-13 12:03:28 -04:00
}
2024-03-15 18:22:44 -04:00
@Override
2025-03-12 20:12:01 -04:00
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (!par1World.isRemote) {
2025-02-09 20:49:45 -05:00
int meta = par1World.getBlockMetadata(i, j, k);
2025-03-12 20:12:01 -04:00
if (meta >= 4) {
2025-02-09 20:49:45 -05:00
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerAnvil.ordinal(), par1World, i, j, k);
} else {
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerCarpentryBench.ordinal(), par1World, i, j, k);
}
2025-03-12 20:12:01 -04:00
}
return true;
2018-09-13 12:03:28 -04:00
}
2024-03-15 18:22:44 -04:00
@Override
2018-09-13 12:03:28 -04:00
public boolean isOpaqueCube()//isOpaqueCube
{
return false;
2024-03-15 18:22:44 -04:00
}
@Override
2018-09-13 12:03:28 -04:00
public int getRenderType()//getRenderType
{
return renderId;
}
2025-03-12 20:12:01 -04:00
2018-09-13 12:03:28 -04:00
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
2024-03-15 18:22:44 -04:00
@Override
2018-09-13 12:03:28 -04:00
public boolean renderAsNormalBlock()//renderAsNormalBlock
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
2025-03-12 20:12:01 -04:00
public IIcon getIcon(int side, int meta) {
if (meta >= 4) {
2025-02-12 17:39:33 -05:00
return Blocks.anvil.getIcon(side, 0);
}
return Blocks.planks.getIcon(side, 0);
2018-09-13 12:03:28 -04:00
}
2024-03-15 18:22:44 -04:00
@Override
2025-03-12 20:12:01 -04:00
public int damageDropped(int par1) {
return par1 / 4;
2018-09-13 12:03:28 -04:00
}
2024-03-15 18:22:44 -04:00
@Override
2025-03-12 20:12:01 -04:00
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
2018-09-13 12:03:28 -04:00
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
}
2024-03-15 18:22:44 -04:00
@Override
2025-03-12 20:12:01 -04:00
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack item) {
int var6 = MathHelper.floor_double((double) (par5EntityLiving.rotationYaw / 90.0F) + 0.5D) & 3;
2018-09-13 12:03:28 -04:00
par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 + item.getItemDamage() * 4, 2);
}
2025-03-12 20:12:01 -04:00
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileBlockAnvil();
}
2018-09-13 12:03:28 -04:00
}