2013-01-21 02:15:59 +01:00
|
|
|
package mekanism.common;
|
|
|
|
|
2023-01-22 17:18:34 +01:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
2014-07-17 05:53:00 +02:00
|
|
|
import mekanism.api.gas.GasStack;
|
2014-07-18 02:06:51 +02:00
|
|
|
import mekanism.common.entity.EntityFlame;
|
2014-07-17 23:18:53 +02:00
|
|
|
import mekanism.common.item.ItemFlamethrower;
|
2014-02-06 02:22:43 +01:00
|
|
|
import mekanism.common.item.ItemFreeRunners;
|
2013-12-06 22:44:08 +01:00
|
|
|
import mekanism.common.item.ItemGasMask;
|
2013-12-05 21:50:38 +01:00
|
|
|
import mekanism.common.item.ItemJetpack;
|
2013-12-18 02:58:30 +01:00
|
|
|
import mekanism.common.item.ItemJetpack.JetpackMode;
|
2013-12-06 22:44:08 +01:00
|
|
|
import mekanism.common.item.ItemScubaTank;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
2016-03-06 00:28:52 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-01-21 02:15:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-18 02:58:30 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-01-21 02:15:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-05-29 18:55:47 +02:00
|
|
|
import net.minecraft.network.NetHandlerPlayServer;
|
2016-03-06 00:28:52 +01:00
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.MathHelper;
|
2013-01-21 02:15:59 +01:00
|
|
|
|
2023-01-22 17:18:34 +01:00
|
|
|
public class CommonPlayerTickHandler {
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onTick(PlayerTickEvent event) {
|
|
|
|
if (event.phase == Phase.END && event.side == Side.SERVER) {
|
|
|
|
tickEnd(event.player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void tickEnd(EntityPlayer player) {
|
|
|
|
if (player.getEquipmentInSlot(1) != null
|
|
|
|
&& player.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners) {
|
|
|
|
player.stepHeight = 1.002F;
|
|
|
|
} else {
|
|
|
|
if (player.stepHeight == 1.002F) {
|
|
|
|
player.stepHeight = 0.5F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isFlamethrowerOn(player)) {
|
|
|
|
player.worldObj.spawnEntityInWorld(new EntityFlame(player));
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode) {
|
|
|
|
((ItemFlamethrower) player.getCurrentEquippedItem().getItem())
|
|
|
|
.useGas(player.getCurrentEquippedItem());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isJetpackOn(player)) {
|
|
|
|
ItemJetpack jetpack = (ItemJetpack) player.getEquipmentInSlot(3).getItem();
|
|
|
|
|
|
|
|
if (jetpack.getMode(player.getEquipmentInSlot(3)) == JetpackMode.NORMAL) {
|
|
|
|
player.motionY = Math.min(player.motionY + 0.15D, 0.5D);
|
|
|
|
} else if (jetpack.getMode(player.getEquipmentInSlot(3)) == JetpackMode.HOVER) {
|
|
|
|
if ((!Mekanism.keyMap.has(player, KeySync.ASCEND)
|
|
|
|
&& !Mekanism.keyMap.has(player, KeySync.DESCEND))
|
|
|
|
|| (Mekanism.keyMap.has(player, KeySync.ASCEND)
|
|
|
|
&& Mekanism.keyMap.has(player, KeySync.DESCEND))) {
|
|
|
|
if (player.motionY > 0) {
|
|
|
|
player.motionY = Math.max(player.motionY - 0.15D, 0);
|
|
|
|
} else if (player.motionY < 0) {
|
|
|
|
if (!isOnGround(player)) {
|
|
|
|
player.motionY = Math.min(player.motionY + 0.15D, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Mekanism.keyMap.has(player, KeySync.ASCEND)) {
|
|
|
|
player.motionY = Math.min(player.motionY + 0.15D, 0.2D);
|
|
|
|
} else if (Mekanism.keyMap.has(player, KeySync.DESCEND)) {
|
|
|
|
if (!isOnGround(player)) {
|
|
|
|
player.motionY = Math.max(player.motionY - 0.15D, -0.2D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.fallDistance = 0.0F;
|
|
|
|
|
|
|
|
if (player instanceof EntityPlayerMP) {
|
|
|
|
MekanismUtils.setPrivateValue(
|
|
|
|
((EntityPlayerMP) player).playerNetServerHandler,
|
|
|
|
0,
|
|
|
|
NetHandlerPlayServer.class,
|
|
|
|
ObfuscatedNames.NetHandlerPlayServer_floatingTickCount
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
jetpack.useGas(player.getEquipmentInSlot(3));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGasMaskOn(player)) {
|
|
|
|
ItemScubaTank tank = (ItemScubaTank) player.getEquipmentInSlot(3).getItem();
|
|
|
|
|
|
|
|
final int max = 300;
|
|
|
|
|
|
|
|
tank.useGas(player.getEquipmentInSlot(3));
|
|
|
|
GasStack received
|
|
|
|
= tank.useGas(player.getEquipmentInSlot(3), max - player.getAir());
|
|
|
|
|
|
|
|
if (received != null) {
|
|
|
|
player.setAir(player.getAir() + received.amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.getAir() == max) {
|
|
|
|
for (Object obj : player.getActivePotionEffects()) {
|
|
|
|
if (obj instanceof PotionEffect) {
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
((PotionEffect) obj).onUpdate(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isOnGround(EntityPlayer player) {
|
|
|
|
int x = MathHelper.floor_double(player.posX);
|
|
|
|
int y = (int) Math.round(player.posY - player.yOffset - 1);
|
|
|
|
int z = MathHelper.floor_double(player.posZ);
|
|
|
|
|
|
|
|
Block b = player.worldObj.getBlock(x, y, z);
|
|
|
|
AxisAlignedBB box = b.getCollisionBoundingBoxFromPool(player.worldObj, x, y, z);
|
|
|
|
AxisAlignedBB playerBox = player.boundingBox.copy().offset(0, -0.01, 0);
|
|
|
|
|
|
|
|
return box != null && playerBox.intersectsWith(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isJetpackOn(EntityPlayer player) {
|
|
|
|
ItemStack stack = player.inventory.armorInventory[2];
|
|
|
|
|
|
|
|
if (stack != null && !player.capabilities.isCreativeMode) {
|
|
|
|
if (stack.getItem() instanceof ItemJetpack) {
|
|
|
|
ItemJetpack jetpack = (ItemJetpack) stack.getItem();
|
|
|
|
|
|
|
|
if (jetpack.getGas(stack) != null) {
|
|
|
|
if ((Mekanism.keyMap.has(player, KeySync.ASCEND)
|
|
|
|
&& jetpack.getMode(stack) == JetpackMode.NORMAL)) {
|
|
|
|
return true;
|
|
|
|
} else if (jetpack.getMode(stack) == JetpackMode.HOVER) {
|
|
|
|
if ((!Mekanism.keyMap.has(player, KeySync.ASCEND)
|
|
|
|
&& !Mekanism.keyMap.has(player, KeySync.DESCEND))
|
|
|
|
|| (Mekanism.keyMap.has(player, KeySync.ASCEND)
|
|
|
|
&& Mekanism.keyMap.has(player, KeySync.DESCEND))) {
|
|
|
|
return !player.onGround;
|
|
|
|
} else if (Mekanism.keyMap.has(player, KeySync.DESCEND)) {
|
|
|
|
return !player.onGround;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isGasMaskOn(EntityPlayer player) {
|
|
|
|
ItemStack tank = player.inventory.armorInventory[2];
|
|
|
|
ItemStack mask = player.inventory.armorInventory[3];
|
|
|
|
|
|
|
|
if (tank != null && mask != null) {
|
|
|
|
if (tank.getItem() instanceof ItemScubaTank
|
|
|
|
&& mask.getItem() instanceof ItemGasMask) {
|
|
|
|
ItemScubaTank scubaTank = (ItemScubaTank) tank.getItem();
|
|
|
|
|
|
|
|
if (scubaTank.getGas(tank) != null) {
|
|
|
|
if (scubaTank.getFlowing(tank)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isFlamethrowerOn(EntityPlayer player) {
|
|
|
|
if (Mekanism.flamethrowerActive.contains(player.getCommandSenderName())) {
|
|
|
|
if (player.getCurrentEquippedItem() != null
|
|
|
|
&& player.getCurrentEquippedItem().getItem()
|
|
|
|
instanceof ItemFlamethrower) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 02:15:59 +01:00
|
|
|
}
|