use of stevekung.mods.moreplanets.tileentity.TileEntityShieldGenerator in project MorePlanets by SteveKunG.
the class BlockShieldGenerator method harvestBlock.
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tile, ItemStack heldStack) {
player.addExhaustion(0.025F);
if (tile instanceof TileEntityShieldGenerator) {
ItemStack machine = new ItemStack(this);
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("ShieldSize", shield.shieldSize);
nbt.setInteger("MaxShieldSize", shield.maxShieldSize);
nbt.setInteger("ShieldDamage", shield.shieldDamage);
nbt.setInteger("MaxShieldDamage", shield.maxShieldDamage);
nbt.setInteger("ShieldCapacity", shield.shieldCapacity);
nbt.setInteger("MaxShieldCapacity", shield.maxShieldCapacity);
nbt.setInteger("ShieldChargeCooldown", shield.shieldChargeCooldown);
nbt.setBoolean("NeedCharged", shield.needCharged);
nbt.setBoolean("EnableShield", shield.enableShield);
nbt.setBoolean("EnableDamage", shield.enableDamage);
ItemStackHelper.saveAllItems(nbt, shield.containingItems);
if (shield.getEnergyStoredGC() > 0) {
nbt.setFloat("EnergyStored", shield.getEnergyStoredGC());
}
machine.setTagCompound(nbt);
Block.spawnAsEntity(world, pos, machine);
}
}
use of stevekung.mods.moreplanets.tileentity.TileEntityShieldGenerator in project MorePlanets by SteveKunG.
the class PacketSimpleMP method handleServerSide.
@Override
public void handleServerSide(EntityPlayer player) {
EntityPlayerMP playerMP = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
World world = player.world;
TileEntity tile;
BlockPos pos;
String type;
switch(this.type) {
case S_FIRE_EXTINGUISH:
pos = (BlockPos) this.data.get(0);
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockToAir(pos);
break;
case S_RESPAWN_PLAYER_NETHER:
if (world instanceof WorldServer) {
WorldServer worldOld = (WorldServer) world;
WorldServer worldNew = WorldDimensionHelper.getStartWorld(worldOld);
BlockPos spawnPos = worldNew.getTopSolidOrLiquidBlock(worldNew.getSpawnPoint());
TeleportUtil.setWarpDimension(playerMP, worldNew, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), WorldUtil.getProviderForNameServer(WorldTickEventHandler.startedDimensionData.planetToBack).getDimension(), true);
player.respawnPlayer();
player.closeScreen();
}
break;
case S_BLACK_HOLE_STORAGE_OPTION:
tile = world.getTileEntity((BlockPos) this.data.get(0));
type = (String) this.data.get(1);
if (tile instanceof TileEntityBlackHoleStorage) {
TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
switch(type) {
case "disable":
storage.disableBlackHole = !storage.disableBlackHole;
break;
case "collect_mode":
storage.modeInt++;
storage.modeInt %= 3;
switch(storage.modeInt) {
case 0:
storage.collectMode = "item";
break;
case 1:
storage.collectMode = "xp";
break;
case 2:
storage.collectMode = "item_and_xp";
break;
}
break;
case "use_hopper":
storage.useHopper = !storage.useHopper;
break;
}
}
break;
case S_SHIELD_VISIBLE:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.setBubbleVisible((boolean) this.data.get(1));
}
break;
case S_ENABLE_SHIELD:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.enableShield = !shield.enableShield;
}
break;
case S_ENABLE_SHIELD_DAMAGE:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.enableDamage = !shield.enableDamage;
}
break;
case S_SHIELD_GENERATOR_OPTION:
tile = world.getTileEntity((BlockPos) this.data.get(0));
int value = (int) this.data.get(1);
type = (String) this.data.get(2);
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
switch(type) {
case "damage":
shield.shieldDamage = value;
break;
case "size":
shield.maxShieldSize = value;
break;
}
}
break;
case S_SWITCH_SHIELD_GENERATOR_GUI:
tile = player.world.getTileEntity((BlockPos) this.data.get(0));
boolean isConfig = (boolean) this.data.get(1);
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
PacketSimpleMP.openShieldGeneratorConfig(playerMP, shield, isConfig);
}
break;
default:
break;
}
}
use of stevekung.mods.moreplanets.tileentity.TileEntityShieldGenerator in project MorePlanets by SteveKunG.
the class BlockShieldGenerator method onUseWrench.
@Override
public boolean onUseWrench(World world, BlockPos pos, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing facing, float hitX, float hitY, float hitZ) {
int change = world.getBlockState(pos).getValue(BlockStateHelper.FACING_HORIZON).rotateY().getHorizontalIndex();
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityShieldGenerator) {
int direction = 0;
if (change == 0) {
direction = 180;
}
if (change == 1) {
direction = -90;
}
if (change == 2) {
direction = 0;
}
if (change == 3) {
direction = 90;
}
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.setFacing(direction);
}
world.setBlockState(pos, this.getStateFromMeta(change), 3);
return true;
}
use of stevekung.mods.moreplanets.tileentity.TileEntityShieldGenerator in project MorePlanets by SteveKunG.
the class BlockShieldGenerator method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack itemStack) {
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;
}
world.setBlockState(pos, this.getDefaultState().withProperty(BlockStateHelper.FACING_HORIZON, placer.getHorizontalFacing().getOpposite()));
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.setFacing(direction);
shield.onCreate(world, pos);
if (itemStack.hasTagCompound()) {
NBTTagCompound nbt = itemStack.getTagCompound();
shield.storage.setEnergyStored(nbt.getFloat("EnergyStored"));
shield.shieldSize = nbt.getFloat("ShieldSize");
shield.maxShieldSize = nbt.getInteger("MaxShieldSize");
shield.shieldDamage = nbt.getInteger("ShieldDamage");
shield.maxShieldDamage = nbt.getInteger("MaxShieldDamage");
shield.shieldCapacity = nbt.getInteger("ShieldCapacity");
shield.maxShieldCapacity = nbt.getInteger("MaxShieldCapacity");
shield.shieldChargeCooldown = nbt.getInteger("ShieldChargeCooldown");
shield.needCharged = nbt.getBoolean("NeedCharged");
shield.enableShield = nbt.getBoolean("EnableShield");
shield.enableDamage = nbt.getBoolean("EnableDamage");
ItemStackHelper.loadAllItems(itemStack.getTagCompound(), shield.containingItems);
}
if (placer instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) placer;
shield.ownerUUID = player.getGameProfile().getId().toString();
}
}
}
use of stevekung.mods.moreplanets.tileentity.TileEntityShieldGenerator in project MorePlanets by SteveKunG.
the class PacketSimpleMP method handleClientSide.
@Override
@SideOnly(Side.CLIENT)
public void handleClientSide(EntityPlayer player) {
BlockPos pos;
switch(this.type) {
case C_ADD_ENTITY_ID:
String entityIDAdd = (String) this.data.get(0);
if (!ClientEventHandler.entityId.contains(entityIDAdd)) {
ClientEventHandler.entityId.add(entityIDAdd);
}
break;
case C_REMOVE_ENTITY_ID:
String entityIDRemove = (String) this.data.get(0);
ClientEventHandler.entityId.remove(entityIDRemove);
break;
case C_REMOVE_GUIDE_POS:
pos = (BlockPos) this.data.get(0);
ClientEventHandler.receiverRenderPos.remove(pos);
break;
case C_RELOAD_RENDERER:
ClientEventHandler.loadRenderers = true;
break;
case C_SWITCH_SHIELD_GENERATOR_GUI:
pos = (BlockPos) this.data.get(0);
boolean isConfig = (boolean) this.data.get(2);
if (pos != null) {
TileEntity tile = player.world.getTileEntity(pos);
if (tile != null && tile instanceof TileEntityShieldGenerator) {
FMLClientHandler.instance().getClient().displayGuiScreen(isConfig ? new GuiShieldGeneratorConfig(player.inventory, (TileEntityShieldGenerator) tile) : new GuiShieldGenerator(player.inventory, (TileEntityShieldGenerator) tile));
}
player.openContainer.windowId = (Integer) this.data.get(1);
}
break;
case C_REMOVE_GENERATOR_GUIDE_POS:
pos = (BlockPos) this.data.get(0);
ClientEventHandler.wasteRenderPos.remove(pos);
break;
default:
break;
}
}
Aggregations