use of net.minecraft.world.entity.player.Player in project MinecraftForge by MinecraftForge.
the class PistonEventTest method pistonPre.
@SubscribeEvent
public static void pistonPre(PistonEvent.Pre event) {
if (event.getPistonMoveType() == PistonMoveType.EXTEND) {
Level world = (Level) event.getWorld();
PistonStructureResolver pistonHelper = event.getStructureHelper();
Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
if (world.isClientSide && player != null) {
if (pistonHelper.resolve()) {
player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getToPush().size(), pistonHelper.getToDestroy().size())), player.getUUID());
} else {
player.sendMessage(new TextComponent("Piston won't extend"), player.getUUID());
}
}
if (pistonHelper.resolve()) {
List<BlockPos> posList = pistonHelper.getToPush();
for (BlockPos newPos : posList) {
BlockState state = event.getWorld().getBlockState(newPos);
if (state.getBlock() == Blocks.BLACK_WOOL) {
Block.dropResources(state, world, newPos);
world.setBlockAndUpdate(newPos, Blocks.AIR.defaultBlockState());
}
}
}
// Make the block move up and out of the way so long as it won't replace the piston
BlockPos pushedBlockPos = event.getFaceOffsetPos();
if (world.getBlockState(pushedBlockPos).getBlock() == shiftOnMove.get() && event.getDirection() != Direction.DOWN) {
world.setBlockAndUpdate(pushedBlockPos, Blocks.AIR.defaultBlockState());
world.setBlockAndUpdate(pushedBlockPos.above(), shiftOnMove.get().defaultBlockState());
}
// Block pushing cobblestone (directly, indirectly works)
event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos()).getBlock() == Blocks.COBBLESTONE);
} else {
boolean isSticky = event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.STICKY_PISTON;
Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
if (event.getWorld().isClientSide() && player != null) {
if (isSticky) {
BlockPos targetPos = event.getFaceOffsetPos().relative(event.getDirection());
boolean canPush = PistonBaseBlock.isPushable(event.getWorld().getBlockState(targetPos), (Level) event.getWorld(), event.getFaceOffsetPos(), event.getDirection().getOpposite(), false, event.getDirection());
boolean isAir = event.getWorld().isEmptyBlock(targetPos);
player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will retract moving %d blocks", !isAir && canPush ? 1 : 0)), player.getUUID());
} else {
player.sendMessage(new TextComponent("Piston will retract"), player.getUUID());
}
}
// Offset twice to see if retraction will pull cobblestone
event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos().relative(event.getDirection())).getBlock() == Blocks.COBBLESTONE && isSticky);
}
}
use of net.minecraft.world.entity.player.Player in project MinecraftForge by MinecraftForge.
the class ForgeIngameGui method renderAir.
protected void renderAir(int width, int height, PoseStack mStack) {
minecraft.getProfiler().push("air");
Player player = (Player) this.minecraft.getCameraEntity();
RenderSystem.enableBlend();
int left = width / 2 + 91;
int top = height - right_height;
int air = player.getAirSupply();
if (player.isEyeInFluid(FluidTags.WATER) || air < 300) {
int full = Mth.ceil((double) (air - 2) * 10.0D / 300.0D);
int partial = Mth.ceil((double) air * 10.0D / 300.0D) - full;
for (int i = 0; i < full + partial; ++i) {
blit(mStack, left - i * 8 - 9, top, (i < full ? 16 : 25), 18, 9, 9);
}
right_height += 10;
}
RenderSystem.disableBlend();
minecraft.getProfiler().pop();
}
use of net.minecraft.world.entity.player.Player in project MinecraftForge by MinecraftForge.
the class ForgeIngameGui method renderHealthMount.
protected void renderHealthMount(int width, int height, PoseStack mStack) {
Player player = (Player) minecraft.getCameraEntity();
Entity tmp = player.getVehicle();
if (!(tmp instanceof LivingEntity))
return;
bind(GUI_ICONS_LOCATION);
boolean unused = false;
int left_align = width / 2 + 91;
minecraft.getProfiler().popPush("mountHealth");
RenderSystem.enableBlend();
LivingEntity mount = (LivingEntity) tmp;
int health = (int) Math.ceil((double) mount.getHealth());
float healthMax = mount.getMaxHealth();
int hearts = (int) (healthMax + 0.5F) / 2;
if (hearts > 30)
hearts = 30;
final int MARGIN = 52;
final int BACKGROUND = MARGIN + (unused ? 1 : 0);
final int HALF = MARGIN + 45;
final int FULL = MARGIN + 36;
for (int heart = 0; hearts > 0; heart += 20) {
int top = height - right_height;
int rowCount = Math.min(hearts, 10);
hearts -= rowCount;
for (int i = 0; i < rowCount; ++i) {
int x = left_align - i * 8 - 9;
blit(mStack, x, top, BACKGROUND, 9, 9, 9);
if (i * 2 + 1 + heart < health)
blit(mStack, x, top, FULL, 9, 9, 9);
else if (i * 2 + 1 + heart == health)
blit(mStack, x, top, HALF, 9, 9, 9);
}
right_height += 10;
}
RenderSystem.disableBlend();
}
use of net.minecraft.world.entity.player.Player in project MinecraftForge by MinecraftForge.
the class ForgeIngameGui method renderFood.
public void renderFood(int width, int height, PoseStack mStack) {
minecraft.getProfiler().push("food");
Player player = (Player) this.minecraft.getCameraEntity();
RenderSystem.enableBlend();
int left = width / 2 + 91;
int top = height - right_height;
right_height += 10;
// Unused flag in vanilla, seems to be part of a 'fade out' mechanic
boolean unused = false;
FoodData stats = minecraft.player.getFoodData();
int level = stats.getFoodLevel();
for (int i = 0; i < 10; ++i) {
int idx = i * 2 + 1;
int x = left - i * 8 - 9;
int y = top;
int icon = 16;
byte background = 0;
if (minecraft.player.hasEffect(MobEffects.HUNGER)) {
icon += 36;
background = 13;
}
// Probably should be a += 1 but vanilla never uses this
if (unused)
background = 1;
if (player.getFoodData().getSaturationLevel() <= 0.0F && tickCount % (level * 3 + 1) == 0) {
y = top + (random.nextInt(3) - 1);
}
blit(mStack, x, y, 16 + background * 9, 27, 9, 9);
if (idx < level)
blit(mStack, x, y, icon + 36, 27, 9, 9);
else if (idx == level)
blit(mStack, x, y, icon + 45, 27, 9, 9);
}
RenderSystem.disableBlend();
minecraft.getProfiler().pop();
}
use of net.minecraft.world.entity.player.Player in project MyPet by xXKeyleXx.
the class EntityMyEnderman method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SHEARS && getMyPet().hasBlock() && getOwner().getPlayer().isSneaking()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getBlock()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setBlock(null);
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
return InteractionResult.CONSUME;
} else if (getMyPet().getBlock() == null && Util.isBetween(1, 255, Item.getId(itemStack.getItem())) && getOwner().getPlayer().isSneaking()) {
getMyPet().setBlock(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
Aggregations