use of stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver in project MorePlanets by SteveKunG.
the class BlockDarkEnergyReceiver method harvestBlock.
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tile, ItemStack itemStack) {
ItemStack machine = new ItemStack(this);
player.addExhaustion(0.025F);
if (tile instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver electric = (TileEntityDarkEnergyReceiver) tile;
if (electric.getEnergyStoredGC() > 0) {
machine.setTagCompound(new NBTTagCompound());
machine.getTagCompound().setFloat("EnergyStored", electric.getEnergyStoredGC());
}
if (!electric.successful && !electric.failed) {
Block.spawnAsEntity(world, pos, machine);
}
}
}
use of stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver in project MorePlanets by SteveKunG.
the class BlockDarkEnergyReceiver method randomDisplayTick.
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver dark = (TileEntityDarkEnergyReceiver) tile;
if (dark.activated && !dark.successful) {
for (int i = 0; i < 32; ++i) {
double d0 = pos.getX() + rand.nextFloat();
double d1 = pos.getY() + rand.nextFloat();
double d2 = pos.getZ() + rand.nextFloat();
double d3 = (rand.nextFloat() - 0.5D) * 0.5D;
double d4 = (rand.nextFloat() - 0.5D) * 0.5D;
double d5 = (rand.nextFloat() - 0.5D) * 0.5D;
int j = rand.nextInt(2) * 2 - 1;
d2 = pos.getZ() + 0.5D + 0.25D * j;
d5 = rand.nextFloat() * 2.0F * j;
MorePlanetsCore.PROXY.spawnParticle(EnumParticleTypesMP.DARK_PORTAL, d0, d1, d2, d3, d4, d5);
}
for (int i = 0; i < 32; ++i) {
double d0 = pos.getX() + rand.nextFloat();
double d1 = pos.getY() + rand.nextFloat();
double d2 = pos.getZ() + rand.nextFloat();
double d3 = (rand.nextFloat() - 0.5D) * 0.5D;
double d4 = (rand.nextFloat() - 0.5D) * 0.5D;
double d5 = (rand.nextFloat() - 0.5D) * 0.5D;
int j = rand.nextInt(2) * 2 - 1;
d0 = pos.getX() + 0.5D + 0.25D * j;
d3 = rand.nextFloat() * 2.0F * j;
MorePlanetsCore.PROXY.spawnParticle(EnumParticleTypesMP.DARK_PORTAL, d0, d1, d2, d3, d4, d5);
}
}
}
}
use of stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver in project MorePlanets by SteveKunG.
the class BlockDarkEnergyReceiver method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver receiver = (TileEntityDarkEnergyReceiver) tile;
receiver.onDestroy(tile);
GalacticraftCore.packetPipeline.sendToDimension(new PacketSimpleMP(EnumSimplePacketMP.C_REMOVE_GUIDE_POS, world.provider.getDimension(), receiver.getPos()), world.provider.getDimension());
}
super.breakBlock(world, pos, state);
}
use of stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver in project MorePlanets by SteveKunG.
the class BlockDarkEnergyReceiver method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
} else {
if (player.isSneaking()) {
if (world.getTileEntity(pos) instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver tile = (TileEntityDarkEnergyReceiver) world.getTileEntity(pos);
if (TileEntityDarkEnergyReceiver.checkValidMultiblock(pos, world)) {
for (Map.Entry<BlockPos, IBlockState> list : TileEntityDarkEnergyReceiver.multiBlockLists.entrySet()) {
BlockPos blockpos = list.getKey();
IBlockState blockstate = list.getValue();
BlockPos newPos = pos.add(blockpos);
JsonUtil json = new JsonUtil();
if (world.getBlockState(newPos) != blockstate) {
Item item = Item.getItemFromBlock(blockstate.getBlock());
String name = item.getItemStackDisplayName(new ItemStack(item, 1, blockstate.getBlock().getMetaFromState(blockstate)));
player.sendMessage(json.text("Missing block " + name + " at " + newPos.getX() + " " + newPos.getY() + " " + newPos.getZ()).setStyle(json.red()));
}
}
} else {
if (!tile.disabled) {
if (tile.getEnergyStoredGC() > 20000.0F) {
if (!tile.isActivated()) {
tile.setActivated(true);
tile.getWorld().playSound(player, tile.getPos(), MPSounds.MACHINE_START, SoundCategory.BLOCKS, 1.0F, 1.0F);
player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_success.message")).setStyle(new JsonUtil().colorFromConfig("green")));
return true;
} else {
player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_already_active.message")).setStyle(new JsonUtil().red()));
return false;
}
} else {
if (!tile.isActivated()) {
player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_no_power.message")).setStyle(new JsonUtil().red()));
return false;
}
}
} else {
player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_disabled.message")).setStyle(new JsonUtil().red()));
return false;
}
}
}
} else {
if (world.getTileEntity(pos) instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver tile = (TileEntityDarkEnergyReceiver) world.getTileEntity(pos);
if (tile.failedTick > 0 && !tile.successful) {
int failedTick = 600 - tile.failedTick;
String s = "s";
if (failedTick < 40) {
s = "";
}
player.sendMessage(new JsonUtil().text(GCCoreUtil.translateWithFormat("gui.dark_energy_malfunction.message", this.ticksToElapsedTime(failedTick)) + " second" + s + "!").setStyle(new JsonUtil().red()));
return false;
} else {
if (!tile.failed) {
player.openGui(MorePlanetsCore.MOD_ID, -1, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
}
}
}
return false;
}
use of stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver in project MorePlanets by SteveKunG.
the class BlockDarkEnergyReceiver method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack heldStack) {
int angle = MathHelper.floor(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
int change = EnumFacing.getHorizontal(angle).getOpposite().getHorizontalIndex();
int direction = 0;
if (change == 0) {
direction = 180;
}
if (change == 1) {
direction = -90;
}
if (change == 2) {
direction = 0;
}
if (change == 3) {
direction = 90;
}
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityDarkEnergyReceiver) {
TileEntityDarkEnergyReceiver energy = (TileEntityDarkEnergyReceiver) world.getTileEntity(pos);
energy.onCreate(world, pos);
energy.setFacing(direction);
if (heldStack.hasTagCompound() && heldStack.getTagCompound().hasKey("EnergyStored")) {
energy.storage.setEnergyStored(heldStack.getTagCompound().getFloat("EnergyStored"));
}
}
}
Aggregations