Search in sources :

Example 1 with PlayerEntity

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

the class SoulGlassBlock method onEntityCollision.

@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
    if (entity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) entity;
        boolean sinking = player.getLookVec().y < -0.75D;
        CompoundNBT playerData = player.getPersistentData();
        Direction shootDirection = null;
        if (!player.isPotionActive(NetherExEffects.SOUL_SUCKED.get())) {
            playerData.remove(SHOOT_DIRECTION_KEY);
        }
        if (playerData.contains(SHOOT_DIRECTION_KEY)) {
            shootDirection = Direction.byIndex(playerData.getInt(SHOOT_DIRECTION_KEY));
        }
        if (player.isShiftKeyDown()) {
            if (!sinking) {
                if (shootDirection == null) {
                    shootDirection = player.getHorizontalFacing().getOpposite();
                }
                Block blockOneBack = world.getBlockState(pos.offset(shootDirection)).getBlock();
                Block blockTwoBack = world.getBlockState(pos.offset(shootDirection, 2)).getBlock();
                Block blockThreeBack = world.getBlockState(pos.offset(shootDirection, 3)).getBlock();
                if (blockOneBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockOneBack == this && blockTwoBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockOneBack == this && blockThreeBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockOneBack == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                }
            } else {
                if (shootDirection == null) {
                    shootDirection = Direction.UP;
                }
                Block blockUpOne = world.getBlockState(pos.up()).getBlock();
                Block blockUpTwo = world.getBlockState(pos.up(2)).getBlock();
                Block blockUpThree = world.getBlockState(pos.up(3)).getBlock();
                if (blockUpOne != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockUpOne == this && blockUpTwo != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockUpOne == this && blockUpThree != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockUpOne == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                    player.setPosition(player.getPosX(), player.prevPosY, player.getPosZ());
                }
                player.setMotion(player.getMotion().mul(1.0D, 0.25D, 1.0D));
            }
        } else {
            EffectInstance effect = player.getActivePotionEffect(NetherExEffects.SOUL_SUCKED.get());
            int amplifier = 1;
            if (effect != null) {
                amplifier = (effect.getAmplifier() + 1);
            }
            Vec3d motion = player.getMotion();
            if (!sinking && shootDirection != null && shootDirection != Direction.UP) {
                Direction playerDirection = shootDirection.getOpposite();
                if (playerDirection == Direction.NORTH) {
                    if (motion.getZ() < 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), 0.5D));
                    }
                } else if (playerDirection == Direction.EAST) {
                    if (motion.getX() > 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(-0.5D, motion.getY(), motion.getZ()));
                    }
                } else if (playerDirection == Direction.SOUTH) {
                    if (motion.getZ() > 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), -0.5D));
                    }
                } else if (playerDirection == Direction.WEST) {
                    if (motion.getX() < 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(0.5D, motion.getY(), motion.getZ()));
                    }
                }
                if (motion.getX() > -6.0D && motion.getX() < 6.0D) {
                    player.setMotion(new Vec3d((motion.getX() * 1.15D * amplifier), motion.getY(), motion.getZ()));
                }
                if (motion.getZ() > -6.0D && motion.getZ() < 6.0D) {
                    player.setMotion(new Vec3d(motion.getX(), motion.getY(), (motion.getZ() * 1.15D * amplifier)));
                }
            } else {
                if (motion.getY() <= 0) {
                    player.setMotion(new Vec3d(motion.getX(), 0.105D, motion.getZ()));
                }
                if (motion.getY() < 1.315D) {
                    player.setMotion(new Vec3d(motion.getX(), (motion.getY() + (amplifier * 0.1D)), motion.getZ()));
                }
            }
        }
        if (shootDirection != null) {
            playerData.putInt(SHOOT_DIRECTION_KEY, shootDirection.getIndex());
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) GlassBlock(net.minecraft.block.GlassBlock) Block(net.minecraft.block.Block) Direction(net.minecraft.util.Direction) EffectInstance(net.minecraft.potion.EffectInstance) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with PlayerEntity

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

the class RenderEventHandler method onFOVChange.

@SubscribeEvent
public static void onFOVChange(FOVUpdateEvent event) {
    PlayerEntity player = event.getEntity();
    if (player.isPotionActive(NetherExEffects.FROZEN.get())) {
        float fov = 1.0F;
        if (player.abilities.isFlying) {
            fov *= 1.1F;
        }
        if (player.isHandActive() && player.getActiveItemStack().getItem() instanceof BowItem) {
            float useCount = (float) player.getItemInUseMaxCount() / 20.0F;
            if (useCount > 1.0F) {
                useCount = 1.0F;
            } else {
                useCount = useCount * useCount;
            }
            fov *= 1.0F - useCount * 0.15F;
        }
        event.setNewfov(fov);
    }
}
Also used : BowItem(net.minecraft.item.BowItem) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with PlayerEntity

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

the class PlayerHandler method onPlayerTick.

@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
    TickEvent.Phase phase = event.phase;
    World world = event.player.getEntityWorld();
    PlayerEntity player = event.player;
    if (phase == TickEvent.Phase.END) {
        if (!world.isRemote) {
            IInventory inventory = player.inventory;
            int mirrorCount = 0;
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack stack = inventory.getStackInSlot(i);
                if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                    mirrorCount++;
                    if (mirrorCount > 1) {
                        ItemEntity item = new ItemEntity(world, player.getPosX(), player.getPosY() + 0.5F, player.getPosZ(), stack);
                        item.setPickupDelay(50);
                        world.addEntity(item);
                        inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                        break;
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemEntity(net.minecraft.entity.item.ItemEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) TickEvent(net.minecraftforge.event.TickEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with PlayerEntity

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

the class PlayerHandler method onPlayerLeftClick.

@SubscribeEvent
public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickBlock event) {
    World world = event.getWorld();
    Direction direction = event.getFace();
    BlockPos pos = event.getPos();
    PlayerEntity player = event.getPlayer();
    if (direction != null) {
        BlockPos offsetPos = pos.offset(direction);
        Block offsetBlock = world.getBlockState(offsetPos).getBlock();
        if (offsetBlock == NetherExBlocks.BLUE_FIRE.get()) {
            world.playEvent(player, 1009, offsetPos, 0);
            world.setBlockState(offsetPos, Blocks.AIR.getDefaultState());
            event.setCanceled(true);
        }
    }
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with PlayerEntity

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

the class PlayerHandler method onPlayerClone.

@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
    PlayerEntity oldPlayer = event.getOriginal();
    PlayerEntity newPlayer = event.getPlayer();
    IInventory oldInventory = oldPlayer.inventory;
    IInventory newInventory = newPlayer.inventory;
    if (event.isWasDeath()) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < oldInventory.getSizeInventory(); i++) {
            ItemStack stack = oldInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                NBTHelper.ensureTagExists(stack);
                if (stack.getTag().contains("SpawnPoint") && (stack.getDamage() < (stack.getMaxDamage() - 1))) {
                    stack.damageItem(1, newPlayer, entity -> {
                    });
                }
                newInventory.setInventorySlotContents(i, stack);
                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")));
                    BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                    if (spawnDimension != null) {
                        newPlayer.setSpawnDimenion(spawnDimension);
                        newPlayer.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) 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