equivalent-exchange-3/src/main/java/com/pahimar/ee3/block/BlockAludel.java

261 lines
8.5 KiB
Java
Raw Normal View History

package com.pahimar.ee3.block;
2023-01-03 17:47:36 +01:00
import java.util.Random;
2014-07-04 22:11:39 +02:00
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.init.ModBlocks;
2014-09-19 21:55:28 +02:00
import com.pahimar.ee3.reference.GUIs;
import com.pahimar.ee3.reference.Names;
2014-07-04 22:11:39 +02:00
import com.pahimar.ee3.reference.Particles;
import com.pahimar.ee3.reference.RenderIds;
2014-04-30 03:46:59 +02:00
import com.pahimar.ee3.tileentity.TileEntityAludel;
2014-07-04 22:11:39 +02:00
import com.pahimar.ee3.tileentity.TileEntityGlassBell;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2014-07-04 22:11:39 +02:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
2014-07-04 22:11:39 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2014-07-04 22:11:39 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2014-07-04 22:11:39 +02:00
import net.minecraftforge.common.util.ForgeDirection;
2023-01-03 17:47:36 +01:00
public class BlockAludel extends BlockTileEntityEE {
public BlockAludel() {
super(Material.anvil);
this.setHardness(5.0f);
this.setBlockName(Names.Blocks.ALUDEL);
this.setBlockBounds(0.10F, 0.0F, 0.10F, 0.90F, 1.0F, 0.90F);
}
@Override
2023-01-03 17:47:36 +01:00
public TileEntity createNewTileEntity(World world, int metaData) {
2014-04-30 03:46:59 +02:00
return new TileEntityAludel();
}
@Override
2023-01-03 17:47:36 +01:00
public boolean renderAsNormalBlock() {
return false;
}
2014-07-04 22:11:39 +02:00
@Override
2023-01-03 17:47:36 +01:00
public int getRenderType() {
2014-07-04 22:11:39 +02:00
return RenderIds.aludel;
}
@Override
2023-01-03 17:47:36 +01:00
public boolean isOpaqueCube() {
return false;
}
@Override
2023-01-03 17:47:36 +01:00
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
2014-07-04 22:11:39 +02:00
TileEntity tile = world.getTileEntity(x, y, z);
2023-01-03 17:47:36 +01:00
if (tile instanceof TileEntityAludel) {
if (((TileEntityAludel) tile).getState() == 1) {
switch (((TileEntityAludel) tile).getOrientation()) {
2014-07-04 22:11:39 +02:00
case NORTH:
2023-01-03 17:47:36 +01:00
world.spawnParticle(
Particles.FLAME,
(double) x + 0.5F,
(double) y + 0.33F,
(double) z + 0.175F,
0.0D,
0.0D,
0.0D
);
2014-07-04 22:11:39 +02:00
break;
case SOUTH:
2023-01-03 17:47:36 +01:00
world.spawnParticle(
Particles.FLAME,
(double) x + 0.5F,
(double) y + 0.33F,
(double) z + 0.825F,
0.0D,
0.0D,
0.0D
);
2014-07-04 22:11:39 +02:00
break;
case WEST:
2023-01-03 17:47:36 +01:00
world.spawnParticle(
Particles.FLAME,
(double) x + 0.175F,
(double) y + 0.33F,
(double) z + 0.5F,
0.0D,
0.0D,
0.0D
);
2014-07-04 22:11:39 +02:00
break;
case EAST:
2023-01-03 17:47:36 +01:00
world.spawnParticle(
Particles.FLAME,
(double) x + 0.825F,
(double) y + 0.33F,
(double) z + 0.5F,
0.0D,
0.0D,
0.0D
);
2014-07-04 22:11:39 +02:00
break;
default:
break;
2014-07-04 22:11:39 +02:00
}
2023-01-03 17:47:36 +01:00
world.spawnParticle(
Particles.NORMAL_SMOKE,
(double) x + 0.5F,
(double) y + 0.7F,
(double) z + 0.0F,
0.0D,
0.05D,
0.0D
);
world.spawnParticle(
Particles.NORMAL_SMOKE,
(double) x + 0.5F,
(double) y + 0.7F,
(double) z + 1.0F,
0.0D,
0.05D,
0.0D
);
world.spawnParticle(
Particles.NORMAL_SMOKE,
(double) x + 0.0F,
(double) y + 0.7F,
(double) z + 0.5F,
0.0D,
0.05D,
0.0D
);
world.spawnParticle(
Particles.NORMAL_SMOKE,
(double) x + 1.0F,
(double) y + 0.7F,
(double) z + 0.5F,
0.0D,
0.05D,
0.0D
);
2014-07-04 22:11:39 +02:00
}
}
}
@Override
2023-01-03 17:47:36 +01:00
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
TileEntityAludel tileEntityAludel
= (TileEntityAludel) world.getTileEntity(x, y, z);
tileEntityAludel.hasGlassBell
= world.getTileEntity(x, y + 1, z) instanceof TileEntityGlassBell;
2014-07-04 22:11:39 +02:00
super.onNeighborBlockChange(world, x, y, z, block);
}
@Override
2023-01-03 17:47:36 +01:00
public boolean onBlockActivated(
World world,
int x,
int y,
int z,
EntityPlayer player,
int faceHit,
float par7,
float par8,
float par9
) {
if (player.isSneaking()) {
2014-07-04 22:11:39 +02:00
return false;
2023-01-03 17:47:36 +01:00
} else {
if (!world.isRemote) {
if (world.getTileEntity(x, y, z) instanceof TileEntityAludel
&& world.getTileEntity(x, y + 1, z) instanceof TileEntityGlassBell) {
player.openGui(
EquivalentExchange3.instance,
GUIs.ALUDEL.ordinal(),
world,
x,
y,
z
);
2014-07-04 22:11:39 +02:00
}
}
2023-01-03 17:47:36 +01:00
if (world.getTileEntity(x, y, z) instanceof TileEntityAludel
&& ModBlocks.glassBell.canPlaceBlockAt(world, x, y + 1, z)
&& faceHit == ForgeDirection.UP.ordinal()) {
if (player.getHeldItem() != null
&& player.getHeldItem().getItem() instanceof ItemBlock
&& ((ItemBlock) player.getHeldItem().getItem()).field_150939_a
== ModBlocks.glassBell) {
return false;
}
}
2014-07-04 22:11:39 +02:00
return true;
}
}
@Override
2023-01-03 17:47:36 +01:00
public int getLightValue(IBlockAccess world, int x, int y, int z) {
if (world.getTileEntity(x, y, z) instanceof TileEntityAludel) {
if (((TileEntityAludel) world.getTileEntity(x, y, z)).getState() == 1) {
2014-07-04 22:11:39 +02:00
return 15;
}
}
return super.getLightValue(world, x, y, z);
}
@Override
2023-01-03 17:47:36 +01:00
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
if (world.getTileEntity(x, y + 1, z) instanceof TileEntityGlassBell) {
2014-07-04 22:11:39 +02:00
world.markBlockForUpdate(x, y + 1, z);
2023-01-03 17:47:36 +01:00
// NAME UPDATE - this.worldObj.updateAllLightTypes(this.xCoord, this.yCoord,
// this.zCoord);
2014-07-04 22:11:39 +02:00
world.func_147451_t(x, y + 1, z);
}
super.breakBlock(world, x, y, z, block, meta);
}
@Override
2023-01-03 17:47:36 +01:00
public void onBlockPlacedBy(
World world,
int x,
int y,
int z,
EntityLivingBase entityLiving,
ItemStack itemStack
) {
2014-07-04 22:11:39 +02:00
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
2023-01-03 17:47:36 +01:00
if (world.getTileEntity(x, y + 1, z) instanceof TileEntityGlassBell) {
TileEntityGlassBell tileEntityGlassBell
= (TileEntityGlassBell) world.getTileEntity(x, y + 1, z);
2014-07-04 22:11:39 +02:00
tileEntityGlassBell.setOrientation(ForgeDirection.UP);
2023-01-03 17:47:36 +01:00
if (world.getTileEntity(x, y, z) instanceof TileEntityAludel) {
TileEntityAludel tileEntityAludel
= (TileEntityAludel) world.getTileEntity(x, y, z);
2014-07-04 22:11:39 +02:00
2023-01-03 17:47:36 +01:00
ItemStack itemStackGlassBell = tileEntityGlassBell.getStackInSlot(
TileEntityGlassBell.DISPLAY_SLOT_INVENTORY_INDEX
);
2014-07-04 22:11:39 +02:00
2023-01-03 17:47:36 +01:00
tileEntityGlassBell.setInventorySlotContents(
TileEntityGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, null
);
2014-07-04 22:11:39 +02:00
2023-01-03 17:47:36 +01:00
tileEntityAludel.setInventorySlotContents(
TileEntityAludel.INPUT_INVENTORY_INDEX, itemStackGlassBell
);
2014-07-04 22:11:39 +02:00
tileEntityAludel.hasGlassBell = true;
}
}
}
}