use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class EventHandlerGC method onPlayerRightClickedBlock.
@SubscribeEvent
public void onPlayerRightClickedBlock(PlayerInteractEvent.RightClickBlock event) {
// Skip events triggered from Thaumcraft Golems and other non-players
if (event.getEntityPlayer() == null || event.getEntityPlayer().inventory == null || event.getPos() == null || (event.getPos().getX() == 0 && event.getPos().getY() == 0 && event.getPos().getZ() == 0)) {
return;
}
final World worldObj = event.getEntityPlayer().world;
if (worldObj == null) {
return;
}
final Block idClicked = worldObj.getBlockState(event.getPos()).getBlock();
if (idClicked == Blocks.BED && worldObj.provider instanceof IGalacticraftWorldProvider && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
if (GalacticraftCore.isPlanetsLoaded) {
GCPlayerStats stats = GCPlayerStats.get(event.getEntityPlayer());
if (!stats.hasReceivedBedWarning()) {
event.getEntityPlayer().sendMessage(new TextComponentString(GCCoreUtil.translate("gui.bed_fail.message")));
stats.setReceivedBedWarning(true);
}
}
if (worldObj.provider instanceof WorldProviderSpaceStation) {
// On space stations simply block the bed activation => no explosion
event.setCanceled(true);
return;
}
// Optionally prevent beds from exploding - depends on canRespawnHere() in the WorldProvider interacting with this
EventHandlerGC.bedActivated = true;
if (worldObj.provider.canRespawnHere() && !EventHandlerGC.bedActivated) {
EventHandlerGC.bedActivated = true;
// On planets allow the bed to be used to designate a player spawn point
event.getEntityPlayer().setSpawnChunk(event.getPos(), false, GCCoreUtil.getDimensionID(event.getWorld()));
} else {
EventHandlerGC.bedActivated = false;
}
}
final ItemStack heldStack = event.getEntityPlayer().inventory.getCurrentItem();
final TileEntity tileClicked = worldObj.getTileEntity(event.getPos());
if (!heldStack.isEmpty()) {
if (tileClicked != null && tileClicked instanceof IKeyable) {
if (heldStack.getItem() instanceof IKeyItem) {
if (((IKeyItem) heldStack.getItem()).getTier(heldStack) == -1 || ((IKeyable) tileClicked).getTierOfKeyRequired() == -1 || ((IKeyItem) heldStack.getItem()).getTier(heldStack) == ((IKeyable) tileClicked).getTierOfKeyRequired()) {
event.setCanceled(((IKeyable) tileClicked).onValidKeyActivated(event.getEntityPlayer(), heldStack, event.getFace()));
} else if (!event.getEntityPlayer().isSneaking()) {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
}
} else {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
}
}
if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
if (!worldObj.isRemote) {
if (idClicked != Blocks.TNT && OxygenUtil.noAtmosphericCombustion(event.getEntityPlayer().world.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.getEntityLiving().world, new AxisAlignedBB(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getPos().getX() + 1, event.getPos().getY() + 2, event.getPos().getZ() + 1))) {
event.setCanceled(true);
}
}
}
} else if (tileClicked != null && tileClicked instanceof IKeyable) {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class EventHandlerGC method onPlayerDeath.
@SubscribeEvent
public void onPlayerDeath(PlayerDropsEvent event) {
if (event.getEntityLiving() instanceof EntityPlayerMP) {
GCPlayerStats stats = GCPlayerStats.get(event.getEntityPlayer());
if (!event.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
event.getEntityPlayer().captureDrops = true;
for (int i = stats.getExtendedInventory().getSizeInventory() - 1; i >= 0; i--) {
ItemStack stack = stats.getExtendedInventory().getStackInSlot(i);
if (!stack.isEmpty()) {
event.getEntityPlayer().dropItem(stack, true, false);
stats.getExtendedInventory().setInventorySlotContents(i, ItemStack.EMPTY);
}
}
event.getEntityLiving().captureDrops = false;
}
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class GCPlayerHandler method sendAirRemainingPacket.
protected static void sendAirRemainingPacket(EntityPlayerMP player, GCPlayerStats stats) {
final float f1 = stats.getTankInSlot1().isEmpty() ? 0.0F : stats.getTankInSlot1().getMaxDamage() / 90.0F;
final float f2 = stats.getTankInSlot2().isEmpty() ? 0.0F : stats.getTankInSlot2().getMaxDamage() / 90.0F;
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_AIR_REMAINING, GCCoreUtil.getDimensionID(player.world), new Object[] { MathHelper.floor(stats.getAirRemaining() / f1), MathHelper.floor(stats.getAirRemaining2() / f2), PlayerUtil.getName(player) }), player);
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class GCPlayerHandler method updateSchematics.
protected void updateSchematics(EntityPlayerMP player, GCPlayerStats stats) {
SchematicRegistry.addUnlockedPage(player, SchematicRegistry.getMatchingRecipeForID(0));
SchematicRegistry.addUnlockedPage(player, SchematicRegistry.getMatchingRecipeForID(Integer.MAX_VALUE));
Collections.sort(stats.getUnlockedSchematics());
if (player.connection != null && (stats.getUnlockedSchematics().size() != stats.getLastUnlockedSchematics().size() || (player.ticksExisted - 1) % 100 == 0)) {
Integer[] iArray = new Integer[stats.getUnlockedSchematics().size()];
for (int i = 0; i < iArray.length; i++) {
ISchematicPage page = stats.getUnlockedSchematics().get(i);
iArray[i] = page == null ? -2 : page.getPageID();
}
List<Object> objList = new ArrayList<Object>();
objList.add(iArray);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SCHEMATIC_LIST, GCCoreUtil.getDimensionID(player.world), objList), player);
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class EntityAstroMiner method setDead.
@Override
public void setDead() {
if (!this.world.isRemote && this.playerMP != null) {
GCPlayerStats stats = GCPlayerStats.get(this.playerMP);
if (!this.spawnedInCreative) {
int astroCount = stats.getAstroMinerCount();
if (astroCount > 0) {
stats.setAstroMinerCount(stats.getAstroMinerCount() - 1);
}
}
AsteroidsTickHandlerServer.removeChunkData(stats, this);
}
super.setDead();
if (posBase != null) {
TileEntity tileEntity = posBase.getTileEntity(this.world);
if (tileEntity instanceof TileEntityMinerBase) {
((TileEntityMinerBase) tileEntity).unlinkMiner();
}
}
if (this.soundUpdater != null) {
this.soundUpdater.update();
}
}
Aggregations