2015-08-14 00:46:01 +02:00
|
|
|
package techreborn.events;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-13 18:38:12 +01:00
|
|
|
import net.minecraft.init.MobEffects;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
2015-08-14 01:05:10 +02:00
|
|
|
import net.minecraft.item.Item;
|
2016-12-06 19:22:18 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-08-10 01:51:44 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2015-11-23 20:19:18 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
2015-08-14 00:46:01 +02:00
|
|
|
import techreborn.init.ModItems;
|
2016-08-10 01:51:44 +02:00
|
|
|
import techreborn.power.PowerTickEvent;
|
2015-08-14 00:46:01 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public class TRTickHandler {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
public Item previouslyWearing;
|
|
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
|
2016-10-08 21:46:16 +02:00
|
|
|
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
|
2016-03-25 10:47:34 +01:00
|
|
|
EntityPlayer player = e.player;
|
2016-12-06 19:22:18 +01:00
|
|
|
Item chestslot = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST) != ItemStack.EMPTY
|
2016-10-08 21:46:16 +02:00
|
|
|
? player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() : null;
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-01-01 08:29:32 +01:00
|
|
|
if (previouslyWearing != chestslot && previouslyWearing == ModItems.CLOAKING_DEVICE && player.isInvisible()
|
2016-10-08 21:46:16 +02:00
|
|
|
&& !player.isPotionActive(MobEffects.INVISIBILITY)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
player.setInvisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
previouslyWearing = chestslot;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:54:05 +02:00
|
|
|
int ticksCounted = 0;
|
|
|
|
long tickTime = 0;
|
|
|
|
|
2016-08-10 01:51:44 +02:00
|
|
|
@SubscribeEvent
|
2016-10-08 21:46:16 +02:00
|
|
|
public void worldTick(TickEvent.WorldTickEvent e) {
|
|
|
|
if (e.world.isRemote) {
|
2016-08-10 01:51:44 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-10-03 21:54:05 +02:00
|
|
|
|
|
|
|
long start = System.nanoTime();
|
2017-01-09 13:55:08 +01:00
|
|
|
MinecraftForge.EVENT_BUS.post(new PowerTickEvent(e.world));
|
2016-10-03 21:54:05 +02:00
|
|
|
long elapsed = System.nanoTime() - start;
|
|
|
|
tickTime += elapsed;
|
2016-11-25 14:25:51 +01:00
|
|
|
ticksCounted++;
|
|
|
|
if (ticksCounted == 20 * 5) {
|
2016-10-03 21:54:05 +02:00
|
|
|
//Enable this this line to get some infomation when debuging.
|
|
|
|
//System.out.println("Average powernet tick time over last 5 seconds: " + (tickTime / ticksCounted) + "ns");
|
|
|
|
ticksCounted = 0;
|
|
|
|
tickTime = 0;
|
|
|
|
}
|
2016-08-10 01:51:44 +02:00
|
|
|
}
|
|
|
|
|
2015-08-14 00:46:01 +02:00
|
|
|
}
|