Search in sources :

Example 1 with PotionEffect

use of com.viste.realisticarmortiers.data.PotionEffect in project RealisticArmorTiers by IsakViste.

the class ArmorStorage method writeNBT.

@Nullable
@Override
public INBT writeNBT(Capability<IArmor> capability, IArmor instance, Direction side) {
    NBTTagCompound bigCompoundList = new NBTTagCompound();
    NBTTagList itemTagList = new NBTTagList();
    for (ItemStack item : instance.getItems()) {
        NBTTagCompound tag = new NBTTagCompound();
        tag = item.writeToNBT(tag);
        itemTagList.appendTag(tag);
    }
    NBTTagList setEffectsTagList = new NBTTagList();
    for (PotionEffect potionEffect : instance.getPotionEffects()) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setString("effect", potionEffect.id);
        tag.setInteger("efficiency", potionEffect.efficiency);
        setEffectsTagList.appendTag(tag);
    }
    NBTTagList usedSetEffectsTagList = new NBTTagList();
    for (PotionEffect potionEffect : instance.getPotionEffects()) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setString("effect", potionEffect.id);
        tag.setInteger("efficiency", potionEffect.efficiency);
        tag.setInteger("duration", potionEffect.duration);
        usedSetEffectsTagList.appendTag(tag);
    }
    bigCompoundList.setTag("items", itemTagList);
    bigCompoundList.setTag("setEffects", setEffectsTagList);
    bigCompoundList.setTag("usedSetEffects", usedSetEffectsTagList);
    return bigCompoundList;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 2 with PotionEffect

use of com.viste.realisticarmortiers.data.PotionEffect in project RealisticArmorTiers by IsakViste.

the class EventEquipmentSets method onServerTick.

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent evt) {
    MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
    List<ServerPlayerEntity> playerList = Lists.newArrayList(server.getPlayerList().getPlayers());
    IArmor armors = null;
    List<PotionEffect> setEffects = new ArrayList<>();
    boolean foundWhole = false;
    for (ServerPlayerEntity serverPlayerEntity : playerList) {
        int m;
        List<ItemStack> stacks;
        if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
            armors = (IArmor) serverPlayerEntity.getCapability(ArmorProvider.Armor);
            stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
            int numberOfStack = 0;
            for (ItemStack stack : stacks) {
                if (!stack.isEmpty()) {
                    numberOfStack++;
                }
            }
            if (numberOfStack == armors.getItems().size()) {
                foundWhole = true;
                for (ItemStack stack : stacks) {
                    boolean found = false;
                    if (!stack.isEmpty()) {
                        for (int l = 0; l < armors.getItems().size(); l++) {
                            if (stack.getItem().equals(armors.getItems().get(l).getItem())) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            foundWhole = false;
                            break;
                        }
                    }
                }
            }
        }
        if (foundWhole) {
            setEffects = armors.getPotionEffects();
        } else {
            if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
                if (armors != null) {
                    m = 0;
                    setEffects = armors.getPotionEffects();
                    while (m < setEffects.size()) {
                        RegistryObject<Effect> potionEffect = RegistryObject.of(new ResourceLocation(setEffects.get(m).id), ForgeRegistries.POTIONS);
                        if (potionEffect.isPresent()) {
                            serverPlayerEntity.removeEffect(potionEffect.get());
                        }
                        m++;
                    }
                    armors.removeAllItems();
                    Collection<EffectInstance> potionEffectsPlayer = serverPlayerEntity.getActiveEffects();
                    Iterator<EffectInstance> potionEffects = potionEffectsPlayer.iterator();
                    while (potionEffects.hasNext()) {
                        EffectInstance o = potionEffects.next();
                        ResourceLocation effectResLoc = o.getEffect().getRegistryName();
                        if (effectResLoc == null) {
                            RealisticArmorTiers.LOGGER.warn("Could not find ResourceLocation of " + o.getDescriptionId());
                            continue;
                        }
                        PotionEffect usedPotion = new PotionEffect(effectResLoc.getNamespace() + ":" + o.getEffect().getRegistryName().getPath(), o.getAmplifier(), o.getDuration());
                        armors.addUsedPotionEffect(usedPotion);
                        potionEffects.remove();
                    }
                    stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
                    for (ItemStack stack : stacks) {
                        if (!stack.isEmpty()) {
                            armors.addItem(stack.copy());
                        }
                    }
                }
            } else {
                serverPlayerEntity.removeAllEffects();
            }
            int setNumber = sets.armors.checkIfSet(serverPlayerEntity);
            if (setNumber != -1) {
                setEffects = sets.armors.getPotionEffects(setNumber);
            }
            if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
                if (setEffects != null && armors != null) {
                    armors.addPotionEffectList(setEffects);
                }
            }
        }
        if (armors != null) {
            if (setEffects != null) {
                m = 0;
                while (m < setEffects.size()) {
                    Equiped.addPotionEffect(serverPlayerEntity, armors.getPotionEffects().get(m));
                    m++;
                }
            }
            if (!foundWhole) {
                setEffects = armors.getUsedPotionEffects();
                Equiped.addUsedPotionEffect(serverPlayerEntity, setEffects, armors);
            }
        }
    }
}
Also used : PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) ArrayList(java.util.ArrayList) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IArmor(com.viste.realisticarmortiers.capability.IArmor) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceLocation(net.minecraft.util.ResourceLocation) Effect(net.minecraft.potion.Effect) PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with PotionEffect

use of com.viste.realisticarmortiers.data.PotionEffect in project RealisticArmorTiers by IsakViste.

the class Equiped method addPotionEffectsArmor.

public static void addPotionEffectsArmor(ServerPlayerEntity player, String potion_effect, int efficiency) {
    PotionEffect potionEffect = new PotionEffect(potion_effect, efficiency, 0);
    if (player.getCapability(ArmorProvider.Armor).isPresent()) {
        IArmor armors = (IArmor) player.getCapability(ArmorProvider.Armor);
        armors.addPotionEffect(potionEffect);
    }
    addPotionEffect(player, potionEffect);
}
Also used : PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) IArmor(com.viste.realisticarmortiers.capability.IArmor)

Example 4 with PotionEffect

use of com.viste.realisticarmortiers.data.PotionEffect in project RealisticArmorTiers by IsakViste.

the class Equiped method addPotionEffect.

public static void addPotionEffect(ServerPlayerEntity player, PotionEffect setEffect) {
    EventEquipmentGlobalVar global = new EventEquipmentGlobalVar();
    RegistryObject<Effect> potionEffect = RegistryObject.of(new ResourceLocation(setEffect.id), ForgeRegistries.POTIONS);
    if (player.hasEffect(potionEffect.get())) {
        player.removeEffect(potionEffect.get());
    }
    player.addEffect(new EffectInstance(potionEffect.get(), global.getPotionDur(), setEffect.efficiency - 1));
}
Also used : EventEquipmentGlobalVar(com.viste.realisticarmortiers.data.EventEquipmentGlobalVar) ResourceLocation(net.minecraft.util.ResourceLocation) PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) Effect(net.minecraft.potion.Effect) EffectInstance(net.minecraft.potion.EffectInstance)

Example 5 with PotionEffect

use of com.viste.realisticarmortiers.data.PotionEffect in project RealisticArmorTiers by IsakViste.

the class Equiped method addUsedPotionEffect.

public static void addUsedPotionEffect(ServerPlayerEntity player, List<PotionEffect> potionEffects, IArmor armors) {
    Iterator<PotionEffect> i = potionEffects.iterator();
    while (i.hasNext()) {
        PotionEffect setEffect = i.next();
        if (setEffect.duration > 0 && setEffect.duration < 2000000000) {
            RegistryObject<Effect> potionEffect = RegistryObject.of(new ResourceLocation(setEffect.id), ForgeRegistries.POTIONS);
            if (!player.hasEffect(potionEffect.get())) {
                player.addEffect(new EffectInstance(potionEffect.get(), setEffect.duration, setEffect.efficiency));
                i.remove();
            }
        } else {
            i.remove();
        }
    }
}
Also used : PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) ResourceLocation(net.minecraft.util.ResourceLocation) PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) Effect(net.minecraft.potion.Effect) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

PotionEffect (com.viste.realisticarmortiers.data.PotionEffect)6 ItemStack (net.minecraft.item.ItemStack)3 Effect (net.minecraft.potion.Effect)3 EffectInstance (net.minecraft.potion.EffectInstance)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 IArmor (com.viste.realisticarmortiers.capability.IArmor)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 EventEquipmentGlobalVar (com.viste.realisticarmortiers.data.EventEquipmentGlobalVar)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1