Search in sources :

Example 1 with Player

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);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) PistonStructureResolver(net.minecraft.world.level.block.piston.PistonStructureResolver) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with Player

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();
}
Also used : Player(net.minecraft.world.entity.player.Player)

Example 3 with Player

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();
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player)

Example 4 with Player

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();
}
Also used : Player(net.minecraft.world.entity.player.Player) FoodData(net.minecraft.world.food.FoodData)

Example 5 with Player

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;
}
Also used : CraftMagicNumbers(org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers) MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Items(net.minecraft.world.item.Items) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) Item(net.minecraft.world.item.Item) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior) EntityDataSerializers(net.minecraft.network.syncher.EntityDataSerializers) BlockState(net.minecraft.world.level.block.state.BlockState) BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) InteractionResult(net.minecraft.world.InteractionResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Player(net.minecraft.world.entity.player.Player) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Optional(java.util.Optional) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) CompatManager(de.Keyle.MyPet.compat.v1_17_R1.CompatManager) MyEnderman(de.Keyle.MyPet.api.entity.types.MyEnderman) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) ItemEntity(net.minecraft.world.entity.item.ItemEntity)

Aggregations

Player (net.minecraft.world.entity.player.Player)58 ItemStack (net.minecraft.world.item.ItemStack)53 Level (net.minecraft.world.level.Level)53 InteractionHand (net.minecraft.world.InteractionHand)52 InteractionResult (net.minecraft.world.InteractionResult)51 Items (net.minecraft.world.item.Items)51 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)50 MyPet (de.Keyle.MyPet.api.entity.MyPet)50 InvocationTargetException (java.lang.reflect.InvocationTargetException)50 ItemEntity (net.minecraft.world.entity.item.ItemEntity)49 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)42 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)42 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)42 Bukkit (org.bukkit.Bukkit)39 MyPetApi (de.Keyle.MyPet.MyPetApi)38 Util (de.Keyle.MyPet.api.Util)38 ServerLevel (net.minecraft.server.level.ServerLevel)37 Pair (com.mojang.datafixers.util.Pair)36 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)36 Arrays (java.util.Arrays)36