Search in sources :

Example 1 with IGenericDataStorage

use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method handleFireMessage.

public void handleFireMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunFireMessage message) {
    ItemStack itemStack = player.getItemInHand(message.hand);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("RailGun has no Energy Capability? NBT: " + itemStack.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    LazyOptional<IGenericDataStorage> opSettingCapability = itemStack.getCapability(GENERIC_DATA_STORAGE);
    if (!opSettingCapability.isPresent()) {
        Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
        return;
    }
    IGenericDataStorage settingCapability = opSettingCapability.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    settingCapability.suggestUpdate();
    int energyRequired = settingCapability.getIntegerMap().getOrDefault(RAILGUN_POWER_KEY, OverloadedConfig.INSTANCE.railGun.minEnergy);
    if (energy.getEnergyStored() < energyRequired) {
        player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
        return;
    }
    int energyExtracted = energy.extractEnergy(energyRequired, false);
    @Nullable Entity entity = player.level.getEntity(message.id);
    if (entity == null || !entity.isAlive()) {
        return;
    } else if (player.distanceTo(entity) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
        player.displayClientMessage(new StringTextComponent("Target out of range."), true);
    } else if (entity.hurt(DamageSource.playerAttack(player), (float) (OverloadedConfig.INSTANCE.railGun.damagePerRF * energyExtracted))) {
        Vector3d knockback = message.moveVector.scale(energyExtracted * OverloadedConfig.INSTANCE.railGun.knockbackPerRF);
        entity.push(knockback.x, knockback.y, knockback.z);
    }
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 2 with IGenericDataStorage

use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method getHelmetDataStorage.

@Nonnull
private static IGenericDataStorage getHelmetDataStorage(PlayerEntity player) {
    for (ItemStack stack : player.inventory.armor) {
        if (stack.getItem() instanceof ItemMultiHelmet) {
            IGenericDataStorage cap = stack.getCapability(GENERIC_DATA_STORAGE).orElse(new GenericDataStorage());
            cap.suggestUpdate();
            return cap;
        }
    }
    return new GenericDataStorage();
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) GenericDataStorage(com.cjm721.overloaded.storage.GenericDataStorage) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with IGenericDataStorage

use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method setNoClip.

public static void setNoClip(PlayerEntity player, boolean enabled) {
    IGenericDataStorage storage = getPlayerDataStorage(player);
    final Map<String, Boolean> booleans = storage.getBooleanMap();
    booleans.put(noClip, enabled);
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage)

Example 4 with IGenericDataStorage

use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.

the class ArmorEventHandler method toggleNoClip.

public static boolean toggleNoClip(ServerPlayerEntity player) {
    IGenericDataStorage storage = getPlayerDataStorage(player);
    final Map<String, Boolean> booleans = storage.getBooleanMap();
    if (booleans.containsKey(noClip) && booleans.get(noClip)) {
        booleans.remove(noClip);
        return false;
    } else {
        booleans.put(noClip, true);
        return true;
    }
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage)

Example 5 with IGenericDataStorage

use of com.cjm721.overloaded.storage.IGenericDataStorage 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)

Aggregations

IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)8 ItemStack (net.minecraft.item.ItemStack)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 StringTextComponent (net.minecraft.util.text.StringTextComponent)3 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Overloaded (com.cjm721.overloaded.Overloaded)1 GENERIC_DATA_STORAGE (com.cjm721.overloaded.capabilities.CapabilityGenericDataStorage.GENERIC_DATA_STORAGE)1 GenericSlider (com.cjm721.overloaded.client.gui.button.GenericSlider)1 GuiPositiveFloatTextField (com.cjm721.overloaded.client.gui.button.GuiPositiveFloatTextField)1 ToggleButton (com.cjm721.overloaded.client.gui.button.ToggleButton)1 OverloadedConfig (com.cjm721.overloaded.config.OverloadedConfig)1 ItemMultiHelmet (com.cjm721.overloaded.item.functional.armor.ItemMultiHelmet)1 DataKeys (com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.DataKeys)1 Default (com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.Default)1 MultiArmorSettingsMessage (com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage)1 GenericDataStorage (com.cjm721.overloaded.storage.GenericDataStorage)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Map (java.util.Map)1