Search in sources :

Example 6 with PlayerEntity

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

the class RimeAndSteelItem method onItemUse.

@Override
public ActionResultType onItemUse(ItemUseContext context) {
    World world = context.getWorld();
    PlayerEntity player = context.getPlayer();
    Hand hand = context.getHand();
    BlockPos pos = context.getPos();
    Direction direction = context.getFace();
    pos = pos.offset(direction);
    ItemStack stack = player.getHeldItem(hand);
    if (!player.canPlayerEdit(pos, direction, stack)) {
        return ActionResultType.FAIL;
    } else {
        if (world.isAirBlock(pos)) {
            world.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F);
            world.setBlockState(pos, NetherExBlocks.BLUE_FIRE.get().getDefaultState(), 11);
        }
        stack.damageItem(1, player, entity -> entity.sendBreakAnimation(hand));
        return ActionResultType.SUCCESS;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 7 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method onLivingAttackedEvent.

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onLivingAttackedEvent(LivingAttackEvent event) {
    Entity entity = event.getEntity();
    if (!(entity instanceof PlayerEntity))
        return;
    PlayerEntity player = ((PlayerEntity) entity);
    boolean setEquipped = isMultiArmorSetEquipped(player);
    if (setEquipped) {
        DamageSource damageSource = event.getSource();
        int energyCost = OverloadedConfig.INSTANCE.multiArmorConfig.baseCost;
        float damageAmount = (float) (event.getAmount() * OverloadedConfig.INSTANCE.multiArmorConfig.damageMultiplier);
        if (damageSource.isBypassMagic())
            damageAmount *= OverloadedConfig.INSTANCE.multiArmorConfig.absoluteDamageMultiplier;
        if (damageSource.isBypassArmor())
            damageAmount *= OverloadedConfig.INSTANCE.multiArmorConfig.unblockableMultiplier;
        if (damageAmount > Integer.MAX_VALUE)
            return;
        energyCost += damageAmount;
        // Overflow
        if (energyCost < 0)
            return;
        if (extractEnergy(player, energyCost, false)) {
            event.setCanceled(true);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) DamageSource(net.minecraft.util.DamageSource) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 8 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method onPlayerTickEvent.

@SubscribeEvent
public void onPlayerTickEvent(@Nonnull TickEvent.PlayerTickEvent event) {
    PlayerEntity player = event.player;
    if (player == null || player.dead)
        return;
    IGenericDataStorage playerDataStorage = getPlayerDataStorage(player);
    if (isMultiArmorSetEquipped(player) && hasEnergy(player)) {
        IGenericDataStorage armorDataStorage = getHelmetDataStorage(player);
        Map<String, Boolean> armorBooleans = armorDataStorage.getBooleanMap();
        playerDataStorage.getBooleanMap().put(set, true);
        AttributeModifier modifier = player.getAttribute(Attributes.MAX_HEALTH).getModifier(HEALTH_MODIFIER);
        if (modifier == null) {
            player.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier(HEALTH_MODIFIER, "Max Health", 100, AttributeModifier.Operation.ADDITION));
        }
        if (armorBooleans.getOrDefault(DataKeys.FLIGHT, Default.FLIGHT)) {
            tryEnableFlight(player, playerDataStorage, armorDataStorage, event.side);
        } else {
            disableFlight(player, event.side);
        }
        if (armorBooleans.getOrDefault(DataKeys.FEED, Default.FEED)) {
            tryFeedPlayer(player, event.side);
        }
        if (armorBooleans.getOrDefault(DataKeys.HEAL, Default.HEAL)) {
            tryHealPlayer(player, event.side);
        }
        if (armorBooleans.getOrDefault(DataKeys.REMOVE_HARMFUL, Default.REMOVE_HARMFUL)) {
            tryRemoveHarmful(player, event.side);
        }
        if (armorBooleans.getOrDefault(DataKeys.EXTINGUISH, Default.EXTINGUISH)) {
            tryExtinguish(player, event.side);
        }
        if (armorBooleans.getOrDefault(DataKeys.GIVE_AIR, Default.GIVE_AIR)) {
            tryGiveAir(player, event.side);
        }
        tryGroundSpeed(player, armorDataStorage, event.side);
    } else {
        Map<String, Boolean> boolMap = playerDataStorage.getBooleanMap();
        if (boolMap.containsKey(set) && boolMap.get(set)) {
            boolMap.put(set, false);
            disableFlight(player, event.side);
            disableNoClip(player, playerDataStorage);
            disableGroundSpeed(player, event.side);
            player.getAttribute(Attributes.MAX_HEALTH).removeModifier(HEALTH_MODIFIER);
            player.setHealth(Math.min(player.getHealth(), player.getMaxHealth()));
        }
    }
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 9 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method onLivingUpdateEvent.

@SubscribeEvent
public void onLivingUpdateEvent(LivingEvent.LivingUpdateEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof PlayerEntity && isMultiArmorSetEquipped((PlayerEntity) entity)) {
        PlayerEntity player = ((PlayerEntity) entity);
        tryEnableNoClip(player, getPlayerDataStorage(player), getHelmetDataStorage(player), LogicalSide.SERVER);
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 10 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.

the class RenderMultiToolAssist method renderWorldLastEvent.

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    float partialTick = Minecraft.getInstance().getFrameTime();
    PlayerEntity player = Minecraft.getInstance().player;
    if (player.getMainHandItem().getItem() != ModItems.multiTool)
        return;
    RayTraceResult resultPick = player.pick(OverloadedConfig.INSTANCE.multiToolConfig.reach, partialTick, false);
    if (resultPick.getType() == RayTraceResult.Type.MISS || !(resultPick instanceof BlockRayTraceResult)) {
        return;
    }
    BlockRayTraceResult result = ((BlockRayTraceResult) resultPick);
    ItemStack stack = ModItems.multiTool.getSelectedBlockItemStack(player.getMainHandItem());
    BlockState state;
    if (stack.getItem() instanceof BlockItem) {
        state = ((BlockItem) stack.getItem()).getBlock().defaultBlockState();
        state = state.getStateAtViewpoint(player.getCommandSenderWorld(), result.getBlockPos(), player.getEyePosition(partialTick));
        state = state.getBlock().getStateForPlacement(new BlockItemUseContextPublic(player.getCommandSenderWorld(), player, Hand.MAIN_HAND, stack, result));
    } else {
        state = Blocks.COBBLESTONE.defaultBlockState();
    }
    switch(getAssistMode()) {
        case PLACE_PREVIEW:
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
            break;
        case REMOVE_PREVIEW:
            renderRemovePreview(event, result);
            break;
        case BOTH_PREVIEW:
            renderRemovePreview(event, result);
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) BlockItemUseContextPublic(com.cjm721.overloaded.util.BlockItemUseContextPublic) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) 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