Java Code Examples for net.minecraft.entity.player.PlayerEntity#isSpectator()

The following examples show how to use net.minecraft.entity.player.PlayerEntity#isSpectator() . 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: MixinPlayerEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void hookInteractEntity(Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> callback) {
	PlayerEntity player = (PlayerEntity) (Object) this;

	if (player.isSpectator()) {
		return;
	}

	int tries = 1;

	if (player.getEntityWorld().isClient) {
		// TODO: Mimicking a stupid forge bug. They fire this *twice* on the client for some reason.
		// I don't know why. It's hooked in ClientPlayerInteractionManager and in PlayerEntity.
		// ClientPlayerInteractionManager just calls directly into PlayerEntity's version.

		tries = 2;
	}

	for (int i = 0; i < tries; i++) {
		ActionResult result = EntityEvents.onInteractEntity(player, entity, hand);

		if (result != null) {
			callback.setReturnValue(result);
			return;
		}
	}
}
 
Example 2
Source File: PlayerEntity_creativeNoClipMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;isSpectator()Z")
)
private boolean canClipTroughWorld(PlayerEntity playerEntity)
{
    return playerEntity.isSpectator() || (CarpetSettings.creativeNoClip && playerEntity.isCreative() && playerEntity.abilities.flying);

}
 
Example 3
Source File: PlayerEntity_creativeNoClipMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tickMovement", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;isSpectator()Z")
)
private boolean collidesWithEntities(PlayerEntity playerEntity)
{
    return playerEntity.isSpectator() || (CarpetSettings.creativeNoClip && playerEntity.isCreative() && playerEntity.abilities.flying);
}
 
Example 4
Source File: PlayerEntity_creativeNoClipMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "updateSize", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;isSpectator()Z")
)
private boolean spectatorsDontPose(PlayerEntity playerEntity)
{
    return playerEntity.isSpectator() || (CarpetSettings.creativeNoClip && playerEntity.isCreative() && playerEntity.abilities.flying);
}