use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase in project Galacticraft by micdoodle8.
the class ItemAstroMiner method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity tile = null;
if (worldIn.isRemote || playerIn == null) {
return false;
} else {
final Block id = worldIn.getBlockState(pos).getBlock();
if (id == GCBlocks.fakeBlock) {
tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityMulti) {
tile = ((TileEntityMulti) tile).getMainBlockTile();
}
}
if (id == AsteroidBlocks.minerBaseFull) {
tile = worldIn.getTileEntity(pos);
}
if (tile instanceof TileEntityMinerBase) {
if (worldIn.provider instanceof WorldProviderSpaceStation) {
playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner7.fail")));
return false;
}
if (((TileEntityMinerBase) tile).getLinkedMiner() != null) {
playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner.fail")));
return false;
}
// Gives a chance for any loaded Astro Miner to link itself
if (((TileEntityMinerBase) tile).ticks < 15L) {
return false;
}
EntityPlayerMP playerMP = (EntityPlayerMP) playerIn;
GCPlayerStats stats = GCPlayerStats.get(playerIn);
int astroCount = stats.getAstroMinerCount();
if (astroCount >= ConfigManagerAsteroids.astroMinerMax && (!playerIn.capabilities.isCreativeMode)) {
playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner2.fail")));
return false;
}
if (!((TileEntityMinerBase) tile).spawnMiner(playerMP)) {
playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner1.fail") + " " + GCCoreUtil.translate(EntityAstroMiner.blockingBlock.toString())));
return false;
}
if (!playerIn.capabilities.isCreativeMode) {
stats.setAstroMinerCount(stats.getAstroMinerCount() + 1);
--stack.stackSize;
}
return true;
}
}
return false;
}
Aggregations