net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent Java Examples

The following examples show how to use net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Space.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SubscribeEvent
public static void travelToSpace(PlayerTickEvent e) {
	if(e.player.world.isRemote)return;
	if(e.player.dimension == 0 && e.player.posY > 256) {
		e.player.changeDimension(SPACE_DIM_ID, new DimTransfer((WorldServer) e.player.world, e.player.posX, 50, e.player.posZ));
	}else if(e.player.dimension == SPACE_DIM_ID && e.player.posY < 0) {
		e.player.changeDimension(0, new DimTransfer((WorldServer) e.player.world, e.player.posX, 255, e.player.posZ));
		e.player.setFire(30);
	}

	if(damageTick == 0 && e.player.dimension == 78634876) {
		damageTick = 20;
		if(e.player.inventory.armorItemInSlot(3).getItem() != spaceHelm)
		e.player.attackEntityFrom(DamageSource.GENERIC, 2f);
	}else if(e.player.dimension == 78634876){
		if(e.player.world.playerEntities.indexOf(e.player) == 0)
		--damageTick;
	}
}
 
Example #2
Source File: MainCommand.java    From mobycraft with Apache License 2.0 6 votes vote down vote up
/**
 * Used to update containers at the rate specified by the poll rate in the
 * config file
 */
@SubscribeEvent
public void onTick(PlayerTickEvent event) {
	if (event.player.getEntityWorld().isRemote) {
		return;
	}

	count++;
	if (count >= maxCount) {
		sender = event.player;
		if (boxContainers == null) {
			buildCommands.refreshAndBuildContainers();
		} else {
			buildCommands.updateContainers(true);
		}
		count = 0;
	}
}
 
Example #3
Source File: WorldEventsCommon.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent
public void playerTick(PlayerTickEvent event) {
    if (event.phase == Phase.START) {
        EntityPlayer player = event.player;
        //TODO: fix the fall damage
        // @thebest108: what fall damage?
        //                    --DaPorkchop_, 28/03/2017
        if (VSConfig.doValkyriumLifting && !player.isCreative()) {
            for (NonNullList<ItemStack> stackArray : player.inventory.allInventories) {
                for (ItemStack stack : stackArray) {
                    if (stack != null) {
                        if (stack.getItem() instanceof ItemBlock) {
                            ItemBlock blockItem = (ItemBlock) stack.getItem();
                            if (blockItem.getBlock() instanceof BlockValkyriumOre) {
                                player.addVelocity(0, .0025D * stack.stackSize * VSConfig.valkyriumOreForce, 0);
                            }
                        } else if (stack.getItem() instanceof ItemValkyriumCrystal) {
                            player.addVelocity(0, .0025D * stack.stackSize * VSConfig.valkyriumCrystalForce, 0);
                        }
                    }
                }
            }
        }
    }
}
 
Example #4
Source File: VSKeyHandler.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void playerTick(PlayerTickEvent event) {
    if (event.side == Side.SERVER) {
        return;
    }
    if (event.phase == Phase.START) {
        IShipPilotClient clientPilot = (IShipPilotClient) event.player;
        clientPilot.onClientTick();

        if (dismountKey.isKeyDown() && clientPilot.isPilotingATile()) {
            BlockPos pilotedPos = clientPilot.getPosBeingControlled();
            MessagePlayerStoppedPiloting stopPilotingMessage = new MessagePlayerStoppedPiloting(
                pilotedPos);
            ValkyrienSkiesControl.controlNetwork.sendToServer(stopPilotingMessage);
            clientPilot.stopPilotingEverything();
        }
    }
}
 
Example #5
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerTickEvent(PlayerTickEvent event) {
    if (!event.player.world.isRemote) {
        EntityPlayerMP p = (EntityPlayerMP) event.player;

        double[] pos = lastPositions.computeIfAbsent(p, k -> new double[3]);
        try {
            if (pos[0] != p.posX || pos[2] != p.posZ) { // Player has moved
                if (Math.abs(p.posX) > 27000000
                    || Math.abs(p.posZ) > 27000000) { // Player is outside of world
                    // border, tp them back
                    p.attemptTeleport(pos[0], pos[1], pos[2]);
                    p.sendMessage(new TextComponentString(
                        "You can't go beyond 27000000 blocks because airships are stored there!"));
                }
            }
        } catch (NullPointerException e) {
            logger.warn("Nullpointer EventsCommon.java:onPlayerTickEvent");
        }

        pos[0] = p.posX;
        pos[1] = p.posY;
        pos[2] = p.posZ;
    }
}
 
Example #6
Source File: EventCreateWeapon.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SubscribeEvent
public void onCreateWeapon(PlayerTickEvent event)
{
	if (!event.player.getEntityWorld().isRemote)
	{
		if (event.phase == Phase.START)
		{
			for (ItemStack stack : event.player.inventory.mainInventory)
			{
				if (stack != null && (stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow || stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield))
				{
					create(stack, event.player);
				}
			}
		}
	}
}
 
Example #7
Source File: DebugUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onPlayerTickClient(PlayerTickEvent evt) {
  if (evt.side != Side.CLIENT || evt.phase != Phase.END) {
    return;
  }
  RayTraceResult mo = Minecraft.getMinecraft().objectMouseOver;
  if (mo != null && mo.entityHit != null && mo.entityHit instanceof EntityLivingBase) {
    EntityLivingBase el = (EntityLivingBase) mo.entityHit;
    if (el != lastMouseOver) {
      double baseAttack = 0;
      double attack = 0;
      IAttributeInstance damAtt = el.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE);
      if (damAtt != null) {
        baseAttack = damAtt.getBaseValue();
        attack = damAtt.getAttributeValue();
      }
      System.out.println("DebugUtil.onPlayerTickClient: Health: " + el.getMaxHealth() + " Base Damage: " + baseAttack + " Damage: " + attack);
    }
    lastMouseOver = el;
  } else {
    lastMouseOver = null;
  }

}
 
Example #8
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void spawnSentries(PlayerTickEvent event) {
	if (TickEvent.Phase.START.equals(event.phase)) {
		return;
	}
	EntityPlayer player = event.player;
	World world = player.getEntityWorld();

	if (world.isRemote || world.getTotalWorldTime() % 200 != 0) {
		return;
	}

	spawnSentry(player, player.getPosition(), world);
	spawnFugitive(player.getPosition(), world);
}
 
Example #9
Source File: DebugUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent evt) {
  if (evt.side != Side.SERVER || evt.phase != Phase.START) {
    return;
  }
  evt.player.setHealth(evt.player.getMaxHealth());
}
 
Example #10
Source File: Paranoia.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SubscribeEvent
public static void playerTick(PlayerTickEvent e) {
	if(rand.nextInt(80000) < 1) {
		e.player.sendStatusMessage(new TextComponentString(messages[rand.nextInt(messages.length)]), true);
	}
}
 
Example #11
Source File: StateEpisode.java    From malmo with MIT License 4 votes vote down vote up
/** Subclass should overrride this to act on player ticks.*/
protected void onPlayerTick(PlayerTickEvent ev) {}
 
Example #12
Source File: SpaceObjectManager.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
/**
 * Event designed to teleport a player to the spawn point for the station if he'she falls out of the world in space
 * TODO: prevent inf loop if nowhere to fall!
 */
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
	if(event.player.world.provider.getDimension() == Configuration.spaceDimId) {

		if(event.player.posY < 0 && !event.player.world.isRemote) {
			ISpaceObject object = getSpaceStationFromBlockCoords(event.player.getPosition());
			if(object != null) {

				HashedBlockPosition loc = object.getSpawnLocation();

				event.player.fallDistance=0;
				event.player.motionY = 0;
				event.player.setPositionAndUpdate(loc.x, loc.y + 2, loc.z);
				event.player.sendMessage(new TextComponentString("You wake up finding yourself back on the station"));
			}
		}

		int result = Math.abs(2*(((int)event.player.posZ + Configuration.stationSize/2) % (2*Configuration.stationSize) )/Configuration.stationSize);
		if(result == 0 || result == 3) {
			event.player.motionZ = -event.player.motionZ;
			if(result == 0) {
				event.player.setPosition(event.player.posX, event.player.posY, event.player.posZ + (event.player.posZ < 0 ? Math.abs(event.player.posZ % 16) : (16 - event.player.posZ % 16)));
			}
			else
				event.player.setPosition(event.player.posX, event.player.posY, event.player.posZ - (event.player.posZ < 0 ? 16 - Math.abs(event.player.posZ % 16) : (event.player.posZ % 16)));

		}

		//double posX = event.player.posX < 0 ? -event.player.posX - Configuration.stationSize : event.player.posX;

		result = Math.abs(2*(((int)event.player.posX + Configuration.stationSize/2) % (2*Configuration.stationSize) )/Configuration.stationSize);

		if(event.player.posX < -Configuration.stationSize/2)
			if(result == 3)
				result = 0;
			else if(result == 0)
				result = 3;

		if(result == 0 || result == 3) {
			event.player.motionX = -event.player.motionX;
			if(result == 0) {
				event.player.setPosition(event.player.posX + (event.player.posX < 0 ? Math.abs(event.player.posX % 16) : (16 - event.player.posX % 16)), event.player.posY, event.player.posZ);
			}
			else
				event.player.setPosition(event.player.posX - (event.player.posX < 0 ? 16 - Math.abs(event.player.posX % 16) : (event.player.posX % 16)), event.player.posY, event.player.posZ);

		}
	}
}
 
Example #13
Source File: TickHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event)
{
    EntityPlayer player = event.player;

    if (event.side == Side.CLIENT || player.getEntityWorld().isRemote)
    {
        return;
    }

    // Once every 2 seconds
    if (this.playerTickCounter % 40 == 0)
    {
        if (player.isRiding() && player.inventory.hasItemStack(new ItemStack(EnderUtilitiesItems.MOB_HARNESS)))
        {
            ItemMobHarness.addAITask(player.getRidingEntity(), false);
        }

        ItemStack stack = EntityUtils.getHeldItemOfType(player, IChunkLoadingItem.class);

        if (stack.isEmpty() == false)
        {
            NBTTagCompound nbt = stack.getTagCompound();

            // If the player is holding an item that requires a chunk to stay loaded, refresh the timeout value
            if (nbt != null && nbt.getBoolean("ChunkLoadingRequired"))
            {
                TargetData target;

                // Note: There is the possibility that the target or the selected link crystal
                // has been changed since the chunk loading first started, but it just means
                // that the refreshing will not happen, or will happen to the new target chunk,
                // (the one currently active in the item) if that also happens to be chunk loaded by us.

                // In case of modular items, we get the target info from the selected module (= Link Crystal)
                if (stack.getItem() instanceof IModular)
                {
                    target = TargetData.getTargetFromSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL);
                }
                else
                {
                    target = TargetData.getTargetFromItem(stack);
                }

                if (target != null)
                {
                    ChunkLoading.getInstance().refreshChunkTimeout(target.dimension, target.pos.getX() >> 4, target.pos.getZ() >> 4);
                }
            }
        }
    }

    PlayerTaskScheduler.getInstance().runTasks(player.getEntityWorld(), player);
}