2014-09-17 04:58:54 +02:00
|
|
|
package com.pahimar.ee3.block;
|
|
|
|
|
2014-10-10 20:54:07 +02:00
|
|
|
import com.pahimar.ee3.api.Glyph;
|
|
|
|
import com.pahimar.ee3.array.GlyphTextureRegistry;
|
|
|
|
import com.pahimar.ee3.item.ItemChalk;
|
2014-09-17 04:58:54 +02:00
|
|
|
import com.pahimar.ee3.reference.Names;
|
|
|
|
import com.pahimar.ee3.reference.RenderIds;
|
2014-10-10 20:54:07 +02:00
|
|
|
import com.pahimar.ee3.settings.ChalkSettings;
|
2014-09-19 04:38:14 +02:00
|
|
|
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
2014-10-07 06:18:11 +02:00
|
|
|
import com.pahimar.ee3.tileentity.TileEntityEE;
|
2014-10-14 22:08:12 +02:00
|
|
|
import com.pahimar.ee3.util.CommonSoundHelper;
|
2014-10-10 20:54:07 +02:00
|
|
|
import com.pahimar.ee3.util.EntityHelper;
|
2014-09-17 04:58:54 +02:00
|
|
|
import net.minecraft.block.ITileEntityProvider;
|
|
|
|
import net.minecraft.block.material.Material;
|
2014-10-03 21:55:22 +02:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2014-10-10 20:54:07 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-10-03 21:55:22 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-10-10 20:54:07 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-09-17 04:58:54 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-10-10 20:54:07 +02:00
|
|
|
import net.minecraft.util.*;
|
2014-09-17 04:58:54 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2014-09-19 04:38:14 +02:00
|
|
|
public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
|
2014-09-17 04:58:54 +02:00
|
|
|
{
|
2014-09-19 04:38:14 +02:00
|
|
|
public BlockAlchemyArray()
|
2014-09-17 04:58:54 +02:00
|
|
|
{
|
|
|
|
super(Material.circuits);
|
|
|
|
this.setCreativeTab(null);
|
2014-09-19 04:38:14 +02:00
|
|
|
this.setBlockName(Names.Blocks.ALCHEMY_ARRAY);
|
2014-09-17 04:58:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean renderAsNormalBlock()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRenderType()
|
|
|
|
{
|
2014-09-19 04:38:14 +02:00
|
|
|
return RenderIds.alchemyArray;
|
2014-09-17 04:58:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a new instance of a block's tile entity class. Called on placing the block.
|
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param metaData
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World world, int metaData)
|
|
|
|
{
|
2014-09-19 04:38:14 +02:00
|
|
|
return new TileEntityAlchemyArray();
|
2014-09-17 04:58:54 +02:00
|
|
|
}
|
2014-09-25 22:23:45 +02:00
|
|
|
|
2014-10-10 20:54:07 +02:00
|
|
|
// @Override
|
|
|
|
// public boolean canPlaceBlockAt(World world, int x, int y, int z)
|
|
|
|
// {
|
|
|
|
// return super.canPlaceBlockAt(world, x, y, z);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
|
|
|
|
// {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int onBlockPlaced(World world, int x, int y, int z, int sideHit, float hitX, float hitY, float hitZ, int metaData)
|
|
|
|
{
|
|
|
|
return sideHit;
|
|
|
|
}
|
|
|
|
|
2014-10-03 21:55:22 +02:00
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
((TileEntityEE) world.getTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z));
|
2014-10-10 20:54:07 +02:00
|
|
|
|
2014-10-14 22:08:12 +02:00
|
|
|
if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray && entityLiving instanceof EntityPlayer)
|
2014-10-03 21:55:22 +02:00
|
|
|
{
|
2014-10-10 20:54:07 +02:00
|
|
|
NBTTagCompound customEntityData = EntityHelper.getCustomEntityData(entityLiving);
|
|
|
|
ChalkSettings chalkSettings = new ChalkSettings();
|
|
|
|
chalkSettings.readFromNBT(customEntityData);
|
|
|
|
|
2014-10-15 21:51:23 +02:00
|
|
|
// Set adjusted rotation
|
|
|
|
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
|
|
|
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).setRotation(chalkSettings.getRotation(), facing);
|
|
|
|
|
2014-10-10 20:54:07 +02:00
|
|
|
ResourceLocation glyphTexture = GlyphTextureRegistry.getInstance().getResourceLocation(chalkSettings.getIndex());
|
|
|
|
|
|
|
|
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(new Glyph(glyphTexture, GlyphTextureRegistry.getInstance().getGlyphs().get(glyphTexture)), chalkSettings.getSize());
|
|
|
|
|
2014-10-14 22:08:12 +02:00
|
|
|
CommonSoundHelper.playChalkSoundAt((EntityPlayer) entityLiving);
|
2014-10-03 21:55:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 22:13:06 +02:00
|
|
|
@Override
|
2014-10-10 20:54:07 +02:00
|
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int sideHit, float hitX, float hitY, float hitZ)
|
2014-10-09 22:13:06 +02:00
|
|
|
{
|
2014-10-14 22:08:12 +02:00
|
|
|
if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray)
|
2014-10-10 20:54:07 +02:00
|
|
|
{
|
|
|
|
if (entityPlayer.getCurrentEquippedItem() != null && entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemChalk)
|
|
|
|
{
|
|
|
|
NBTTagCompound customEntityData = EntityHelper.getCustomEntityData(entityPlayer);
|
|
|
|
ChalkSettings chalkSettings = new ChalkSettings();
|
|
|
|
chalkSettings.readFromNBT(customEntityData);
|
2014-10-09 22:13:06 +02:00
|
|
|
|
2014-10-10 20:54:07 +02:00
|
|
|
ResourceLocation glyphTexture = GlyphTextureRegistry.getInstance().getResourceLocation(chalkSettings.getIndex());
|
2014-10-09 22:13:06 +02:00
|
|
|
|
2014-10-14 22:08:12 +02:00
|
|
|
if (((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(new Glyph(glyphTexture, GlyphTextureRegistry.getInstance().getGlyphs().get(glyphTexture)), chalkSettings.getSize()))
|
|
|
|
{
|
|
|
|
world.markBlockForUpdate(x, y, z);
|
|
|
|
world.getTileEntity(x, y, z).markDirty();
|
|
|
|
CommonSoundHelper.playChalkSoundAt(entityPlayer);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-10 20:54:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-10-06 01:29:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
|
|
|
|
{
|
2014-10-07 22:20:41 +02:00
|
|
|
return null;
|
2014-10-06 01:29:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
|
|
|
|
* x, y, z, startVec, endVec
|
|
|
|
*/
|
2014-09-25 22:23:45 +02:00
|
|
|
@Override
|
|
|
|
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 startVec, Vec3 endVec)
|
|
|
|
{
|
|
|
|
if (world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray)
|
|
|
|
{
|
2014-10-06 01:29:54 +02:00
|
|
|
TileEntityAlchemyArray tileEntityAlchemyArray = (TileEntityAlchemyArray) world.getTileEntity(x, y, z);
|
|
|
|
|
2014-10-07 06:18:11 +02:00
|
|
|
int largestGlyphSize = tileEntityAlchemyArray.getAlchemyArray().getLargestGlyphSize();
|
|
|
|
|
2014-10-06 01:29:54 +02:00
|
|
|
switch (tileEntityAlchemyArray.getOrientation())
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(0f, 1f, 0f, 1f, 1 - 0.0625f, 1f);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UP:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(0 - (largestGlyphSize - 1) / 2, 0f, 0 - (largestGlyphSize - 1) / 2, 1 + (largestGlyphSize - 1) / 2, 0.0625f, 1 + (largestGlyphSize - 1) / 2);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NORTH:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(0f, 0f, 1 - 0.0625f, 1f, 1f, 1f);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SOUTH:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(0f, 0f, 0f, 1f, 1f, 0.0625f);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EAST:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(0f, 0f, 0f, 0.0625f, 1f, 1f);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WEST:
|
|
|
|
{
|
2014-10-07 06:18:11 +02:00
|
|
|
this.setBlockBounds(1f, 0f, 0f, 1 - 0.0625f, 1f, 1f);
|
2014-10-06 01:29:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UNKNOWN:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-25 22:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.collisionRayTrace(world, x, y, z, startVec, endVec);
|
|
|
|
}
|
2014-09-17 04:58:54 +02:00
|
|
|
}
|