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;
}
}
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);
}
}
}
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()));
}
}
}
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);
}
}
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);
}
}
Aggregations