Search in sources :

Example 31 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project BluePower by Qmunity.

the class ItemSickle method mineBlock.

@Override
public boolean mineBlock(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity entityLiving) {
    boolean used = false;
    if (!(entityLiving instanceof PlayerEntity))
        return false;
    PlayerEntity player = (PlayerEntity) entityLiving;
    if (state.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || state.getBlock() instanceof LeavesBlock) {
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                for (int k = -1; k <= 1; k++) {
                    BlockState blockToCheck = world.getBlockState(pos.offset(i, j, k));
                    if (blockToCheck.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || blockToCheck.getBlock() instanceof LeavesBlock) {
                        if (blockToCheck.canHarvestBlock(world, pos.offset(i, j, k), player)) {
                            world.destroyBlock(pos.offset(i, j, k), true);
                        }
                        used = true;
                    }
                }
            }
        }
        if (used) {
            stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
        }
        return used;
    }
    if ((state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                BlockState meta = world.getBlockState(pos.offset(i, 0, j));
                if (blockToCheck instanceof LilyPadBlock) {
                    if (blockToCheck.canHarvestBlock(meta, world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (!(state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                if (blockToCheck instanceof BushBlock && !(blockToCheck instanceof LilyPadBlock)) {
                    if (blockToCheck.canHarvestBlock(world.getBlockState(pos.offset(i, 0, j)), world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (used) {
        stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
    }
    return used;
}
Also used : BushBlock(net.minecraft.block.BushBlock) BlockState(net.minecraft.block.BlockState) LilyPadBlock(net.minecraft.block.LilyPadBlock) ResourceLocation(net.minecraft.util.ResourceLocation) BushBlock(net.minecraft.block.BushBlock) LilyPadBlock(net.minecraft.block.LilyPadBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 32 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.

the class DullMirrorItem method inventoryTick.

@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
    if (stack.getDamage() == (this.getMaxDamage(stack) - 1)) {
        CompoundNBT compound = NBTHelper.ensureTagExists(stack);
        if (!compound.getBoolean("RemovedSpawn") && entity instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) entity;
            if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                DimensionType bedDimension = DimensionType.byName(new ResourceLocation(compound.getString("BedDimension")));
                if (bedDimension != null) {
                    player.setSpawnDimenion(bedDimension);
                    player.setSpawnPoint(NBTUtil.readBlockPos(compound.getCompound("BedPoint")), true, false, bedDimension);
                    compound.putBoolean("RemovedSpawn", true);
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 33 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerDrop.

@SubscribeEvent
public static void onPlayerDrop(LivingDropsEvent event) {
    LivingEntity livingEntity = event.getEntityLiving();
    Iterator<ItemEntity> iter = event.getDrops().iterator();
    if (livingEntity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) livingEntity;
        while (iter.hasNext()) {
            ItemEntity entityItem = iter.next();
            ItemStack stack = entityItem.getItem();
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
                iter.remove();
                break;
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 34 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerRespawn.

@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
    World world = event.getPlayer().getEntityWorld();
    PlayerEntity player = event.getPlayer();
    PlayerInventory playerInventory = player.inventory;
    if (!world.isRemote) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
            ItemStack stack = playerInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    if (spawnDimension != null && player.dimension != spawnDimension) {
                        MinecraftServer server = world.getServer();
                        if (server != null) {
                            BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                            ((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
                        }
                    }
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 35 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onItemCrafted.

@SubscribeEvent
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
    PlayerEntity player = event.getPlayer();
    ItemStack stack = event.getCrafting();
    if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
        if (stack.getDamage() < stack.getMaxDamage()) {
            CompoundNBT compound = NBTHelper.ensureTagExists(stack);
            compound.putBoolean("RemovedSpawn", false);
            if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                if (spawnDimension != null) {
                    player.setSpawnDimenion(spawnDimension);
                    player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

PlayerEntity (net.minecraft.entity.player.PlayerEntity)46 ItemStack (net.minecraft.item.ItemStack)22 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)19 World (net.minecraft.world.World)17 BlockPos (net.minecraft.util.math.BlockPos)16 CompoundNBT (net.minecraft.nbt.CompoundNBT)13 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12 BlockState (net.minecraft.block.BlockState)10 ResourceLocation (net.minecraft.util.ResourceLocation)7 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)6 Nonnull (javax.annotation.Nonnull)6 AgriCraft (com.infinityraider.agricraft.AgriCraft)5 TileEntity (net.minecraft.tileentity.TileEntity)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)4 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)4 AgriTabs (com.infinityraider.agricraft.content.AgriTabs)4 Names (com.infinityraider.agricraft.reference.Names)4 ItemBase (com.infinityraider.infinitylib.item.ItemBase)4 Nullable (javax.annotation.Nullable)4 Blocks (net.minecraft.block.Blocks)4