Search in sources :

Example 6 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent 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)

Example 7 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method onMouseEvent.

@SubscribeEvent
public void onMouseEvent(InputEvent.MouseScrollEvent event) {
    ClientPlayerEntity player = Minecraft.getInstance().player;
    if (event.getScrollDelta() != 0 && player != null && player.isShiftKeyDown()) {
        ItemStack stack = player.getMainHandItem();
        if (player.isShiftKeyDown() && !stack.isEmpty() && stack.getItem() == this) {
            int powerDelta = Long.signum(Math.round(event.getScrollDelta())) * OverloadedConfig.INSTANCE.railGun.stepEnergy;
            if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), ((ClientProxy) Overloaded.proxy).railGun100x.getKey().getValue())) {
                powerDelta *= 100;
            }
            Overloaded.proxy.networkWrapper.sendToServer(new RailGunSettingsMessage(powerDelta));
            event.setCanceled(true);
        }
    }
}
Also used : RailGunSettingsMessage(com.cjm721.overloaded.network.packets.RailGunSettingsMessage) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 8 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent 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 9 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent 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 10 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent 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)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)87 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ItemStack (net.minecraft.item.ItemStack)17 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)11 ResourceLocation (net.minecraft.util.ResourceLocation)10 World (net.minecraft.world.World)8 Player (net.minecraft.world.entity.player.Player)8 BlockPos (net.minecraft.util.math.BlockPos)7 Entity (net.minecraft.world.entity.Entity)7 ItemStack (net.minecraft.world.item.ItemStack)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 Minecraft (net.minecraft.client.Minecraft)5 BlockPos (net.minecraft.core.BlockPos)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Item (net.minecraft.world.item.Item)5 BlockItem (net.minecraft.item.BlockItem)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4