use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class AsteroidsEventHandlerClient method onClientTick.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
Minecraft minecraft = Minecraft.getMinecraft();
WorldClient world = minecraft.theWorld;
if (world != null) {
if (world.provider instanceof WorldProviderAsteroids) {
if (world.provider.getSkyRenderer() == null) {
world.provider.setSkyRenderer(new SkyProviderAsteroids((IGalacticraftWorldProvider) world.provider));
}
if (world.provider.getCloudRenderer() == null) {
world.provider.setCloudRenderer(new CloudRenderer());
}
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class TransformerHooks method getGravityForEntity.
public static double getGravityForEntity(Entity entity) {
if (entity.worldObj.provider instanceof IGalacticraftWorldProvider) {
if (entity instanceof EntityChicken && !OxygenUtil.isAABBInBreathableAirBlock(entity.worldObj, entity.getEntityBoundingBox())) {
return 0.08D;
}
final IGalacticraftWorldProvider customProvider = (IGalacticraftWorldProvider) entity.worldObj.provider;
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (player.inventory != null) {
int armorModLowGrav = 100;
int armorModHighGrav = 100;
for (int i = 0; i < 4; i++) {
ItemStack armorPiece = player.getCurrentArmor(i);
if (armorPiece != null && armorPiece.getItem() instanceof IArmorGravity) {
armorModLowGrav -= ((IArmorGravity) armorPiece.getItem()).gravityOverrideIfLow(player);
armorModHighGrav -= ((IArmorGravity) armorPiece.getItem()).gravityOverrideIfHigh(player);
}
}
if (armorModLowGrav > 100) {
armorModLowGrav = 100;
}
if (armorModHighGrav > 100) {
armorModHighGrav = 100;
}
if (armorModLowGrav < 0) {
armorModLowGrav = 0;
}
if (armorModHighGrav < 0) {
armorModHighGrav = 0;
}
if (customProvider.getGravity() > 0) {
return 0.08D - (customProvider.getGravity() * armorModLowGrav) / 100;
}
return 0.08D - (customProvider.getGravity() * armorModHighGrav) / 100;
}
}
return 0.08D - customProvider.getGravity();
} else if (entity instanceof IAntiGrav) {
return 0;
} else {
return 0.08D;
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class EventHandlerGC method onPlayerClicked.
@SubscribeEvent
public void onPlayerClicked(PlayerInteractEvent event) {
// Skip events triggered from Thaumcraft Golems and other non-players
if (event.entityPlayer == null || event.entityPlayer.inventory == null || event.pos == null || (event.pos.getX() == 0 && event.pos.getY() == 0 && event.pos.getZ() == 0)) {
return;
}
final World worldObj = event.entityPlayer.worldObj;
if (worldObj == null) {
return;
}
final Block idClicked = worldObj.getBlockState(event.pos).getBlock();
if (idClicked == Blocks.bed && worldObj.provider instanceof IGalacticraftWorldProvider && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
if (GalacticraftCore.isPlanetsLoaded) {
GCPlayerStats stats = GCPlayerStats.get(event.entityPlayer);
if (!stats.hasReceivedBedWarning()) {
event.entityPlayer.addChatMessage(new ChatComponentText(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.entityPlayer.setSpawnChunk(event.pos, false, GCCoreUtil.getDimensionID(event.world));
} else {
EventHandlerGC.bedActivated = false;
}
}
final ItemStack heldStack = event.entityPlayer.inventory.getCurrentItem();
final TileEntity tileClicked = worldObj.getTileEntity(event.pos);
if (heldStack != null) {
if (tileClicked != null && tileClicked instanceof IKeyable) {
if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
return;
} else if (event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
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.entityPlayer, heldStack, event.face));
} else {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
} else if (!event.entityPlayer.isSneaking()) {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
}
}
if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
if (!worldObj.isRemote && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
if (idClicked != Blocks.tnt && OxygenUtil.noAtmosphericCombustion(event.entityPlayer.worldObj.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.entityLiving.worldObj, AxisAlignedBB.fromBounds(event.pos.getX(), event.pos.getY(), event.pos.getZ(), event.pos.getX() + 1, event.pos.getY() + 2, event.pos.getZ() + 1))) {
event.setCanceled(true);
}
}
}
} else if (tileClicked != null && tileClicked instanceof IKeyable) {
if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
return;
}
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class EventHandlerGC method onSoundPlayed.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onSoundPlayed(PlaySoundEvent event) {
// The event.result starts off equal to event.sound, but could have been altered or set to null by another mod
if (event.result == null) {
return;
}
EntityPlayerSP player = FMLClientHandler.instance().getClient().thePlayer;
if (player != null && player.worldObj != null && player.worldObj.provider instanceof IGalacticraftWorldProvider && event != null) {
// Only modify standard game sounds, not music
if (event.result.getAttenuationType() != ISound.AttenuationType.NONE) {
PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(player));
float x = event.result.getXPosF();
float y = event.result.getYPosF();
float z = event.result.getZPosF();
if (gearData == null || gearData.getFrequencyModule() == -1) {
// If the player doesn't have a frequency module, and the player isn't in an oxygenated environment
// Note: this is a very simplistic approach, and nowhere near realistic, but required for performance reasons
AxisAlignedBB bb = AxisAlignedBB.fromBounds(x - 0.0015D, y - 0.0015D, z - 0.0015D, x + 0.0015D, y + 0.0015D, z + 0.0015D);
boolean playerInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player);
boolean soundInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player.worldObj, bb);
if ((!playerInAtmosphere || !soundInAtmosphere)) {
float volume = event.result.getVolume();
// First check for duplicate firing of PlaySoundEvent17 on this handler's own playing of a reduced volume sound (see below)
for (int i = 0; i < this.soundPlayList.size(); i++) {
SoundPlayEntry entry = this.soundPlayList.get(i);
if (entry.name.equals(event.name) && entry.x == x && entry.y == y && entry.z == z && entry.volume == volume) {
this.soundPlayList.remove(i);
return;
}
}
// If it's not a duplicate: play the same sound but at reduced volume
float newVolume = volume / Math.max(0.01F, ((IGalacticraftWorldProvider) player.worldObj.provider).getSoundVolReductionAmount());
this.soundPlayList.add(new SoundPlayEntry(event.name, x, y, z, newVolume));
ISound newSound = new PositionedSoundRecord(event.result.getSoundLocation(), newVolume, event.result.getPitch(), x, y, z);
event.manager.playSound(newSound);
event.result = null;
return;
}
}
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class EventHandlerGC method entityLivingEvent.
@SubscribeEvent
public void entityLivingEvent(LivingUpdateEvent event) {
final EntityLivingBase entityLiving = event.entityLiving;
if (entityLiving instanceof EntityPlayerMP) {
GalacticraftCore.handler.onPlayerUpdate((EntityPlayerMP) entityLiving);
if (GalacticraftCore.isPlanetsLoaded) {
AsteroidsModule.playerHandler.onPlayerUpdate((EntityPlayerMP) entityLiving);
}
return;
}
if (entityLiving.ticksExisted % ConfigManagerCore.suffocationCooldown == 0) {
if (entityLiving.worldObj.provider instanceof IGalacticraftWorldProvider) {
if (!(entityLiving instanceof EntityPlayer) && (!(entityLiving instanceof IEntityBreathable) || !((IEntityBreathable) entityLiving).canBreath()) && !((IGalacticraftWorldProvider) entityLiving.worldObj.provider).hasBreathableAtmosphere()) {
if (!OxygenUtil.isAABBInBreathableAirBlock(entityLiving)) {
GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(entityLiving);
MinecraftForge.EVENT_BUS.post(suffocationEvent);
if (suffocationEvent.isCanceled()) {
return;
}
entityLiving.attackEntityFrom(DamageSourceGC.oxygenSuffocation, Math.max(ConfigManagerCore.suffocationDamage / 2, 1));
GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(entityLiving);
MinecraftForge.EVENT_BUS.post(suffocationEventPost);
}
}
}
}
}
Aggregations