infinity-craft/src/main/java/anvil/infinity/snap/SnapHelper.java

130 lines
5.9 KiB
Java
Raw Normal View History

2019-05-14 18:30:44 +02:00
package anvil.infinity.snap;
2019-06-08 12:49:20 +02:00
import anvil.infinity.capabilities.ICapabilityPlayerData;
2019-05-14 18:30:44 +02:00
import anvil.infinity.config.ConfigHandler;
2019-06-08 12:49:20 +02:00
import anvil.infinity.capabilities.GauntletUserInformation;
2020-04-28 20:00:37 +02:00
import anvil.infinity.config.ModConfig;
2019-05-14 18:30:44 +02:00
import anvil.infinity.helpers.GauntelHelper;
import anvil.infinity.registry.Effects;
2019-06-08 13:17:51 +02:00
import lucraft.mods.lucraftcore.karma.capabilities.CapabilityKarma;
import lucraft.mods.lucraftcore.superpowers.abilities.supplier.IAbilityProvider;
2019-05-14 18:30:44 +02:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
2019-06-08 13:17:51 +02:00
import net.minecraft.entity.monster.EntityMob;
2019-05-14 18:30:44 +02:00
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
2019-05-14 18:30:44 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
2019-05-20 18:10:30 +02:00
import net.minecraft.util.DamageSource;
2019-05-14 18:30:44 +02:00
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.GameType;
2019-05-18 21:15:24 +02:00
import net.minecraft.world.WorldServer;
2019-05-14 18:30:44 +02:00
import net.minecraftforge.fml.common.FMLCommonHandler;
2019-05-18 21:15:24 +02:00
import java.util.ArrayList;
2019-05-14 18:30:44 +02:00
import java.util.List;
import java.util.Random;
public class SnapHelper {
static MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
public static boolean snap(EntityLivingBase entity) {
2019-06-08 12:49:20 +02:00
ICapabilityPlayerData data = GauntletUserInformation.getDataByEntity(entity);
2019-05-14 18:30:44 +02:00
if (GauntelHelper.hasFullGauntlet(entity)) {
2019-05-18 21:15:24 +02:00
WorldServer[] worlds = server.worlds;
2019-06-08 12:49:20 +02:00
if (data.getSnapResult() == SnapResult.KILLHALF) {
2019-05-18 21:15:24 +02:00
List<Entity> entities = new ArrayList<Entity>();
for (int i = 0; i < worlds.length; i++) {
entities.addAll(worlds[i].loadedEntityList);
}
2019-05-14 18:30:44 +02:00
boolean kill = false;
PlayerList players = server.getPlayerList();
TextComponentString msg = new TextComponentString(entity.getName() + ": ");
msg.appendSibling(new TextComponentTranslation("infinity.snap.text"));
msg.getStyle().setColor(TextFormatting.DARK_PURPLE);
msg.getStyle().setBold(true);
players.sendMessage(msg);
Random random = new Random();
for (int i = 0; i < entities.size(); i++) {
if (entities.get(i) != entity && entities.get(i) instanceof EntityLivingBase && kill && !(entities.get(i) instanceof EntityRabbit)) {
EntityLivingBase e = ((EntityLivingBase) entities.get(i));
e.addPotionEffect(new PotionEffect(Effects.snapEffect, random.nextInt((1200 - 10) + 1) - 10));
}
kill = !kill;
}
return true;
2019-06-08 12:49:20 +02:00
} else if (data.getSnapResult() == SnapResult.DESTROYSTONES) {
2019-05-14 20:10:54 +02:00
entity.setHealth(1);
Item mainHand = entity.getHeldItemMainhand().getItem();
Item offHand = entity.getHeldItemOffhand().getItem();
if (mainHand instanceof IAbilityProvider) {
entity.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(mainHand));
}
if (offHand instanceof IAbilityProvider) {
entity.setHeldItem(EnumHand.OFF_HAND, new ItemStack(offHand));
2019-05-14 20:10:54 +02:00
}
2019-05-20 18:10:30 +02:00
entity.attackEntityFrom(DamageSource.MAGIC, (entity.getHealth() / 10) - 0.01f);
2019-05-14 20:10:54 +02:00
2019-05-14 18:30:44 +02:00
2019-06-08 12:49:20 +02:00
} else if (data.getSnapResult() == SnapResult.CREATIVE) {
2020-04-28 20:00:37 +02:00
if (ModConfig.General.snapCreative) {
2019-05-14 18:30:44 +02:00
if (entity instanceof EntityPlayer) {
2019-05-14 20:10:54 +02:00
if (((EntityPlayer) entity).capabilities.isCreativeMode) {
((EntityPlayer) entity).setGameType(GameType.SURVIVAL);
} else {
((EntityPlayer) entity).setGameType(GameType.CREATIVE);
}
2019-05-14 18:30:44 +02:00
return true;
}
}
2019-06-08 12:49:20 +02:00
} else if (data.getSnapResult() == SnapResult.BRINGBACK) {
2019-05-14 20:10:54 +02:00
2019-06-08 12:49:20 +02:00
} else if (data.getSnapResult() == SnapResult.RECREATE) {
} else if (data.getSnapResult() == SnapResult.KILLEVIL) {
List<Entity> entities = new ArrayList<Entity>();
for (int i = 0; i < worlds.length; i++) {
entities.addAll(worlds[i].loadedEntityList);
}
2019-06-08 13:17:51 +02:00
PlayerList players = server.getPlayerList();
TextComponentString msg = new TextComponentString(entity.getName() + ": ");
msg.appendSibling(new TextComponentTranslation("infinity.snap.irontext"));
msg.getStyle().setColor(TextFormatting.RED);
msg.getStyle().setBold(true);
players.sendMessage(msg);
2019-06-08 12:49:20 +02:00
Random random = new Random();
for (int i = 0; i < entities.size(); i++) {
if (entities.get(i) != entity && entities.get(i) instanceof EntityLivingBase) {
EntityLivingBase e = ((EntityLivingBase) entities.get(i));
2019-06-08 13:17:51 +02:00
if (e instanceof EntityMob) {
e.addPotionEffect(new PotionEffect(Effects.snapEffect, random.nextInt((1200 - 10) + 1) - 10));
} else if (e instanceof EntityPlayer && e.hasCapability(CapabilityKarma.KARMA_CAP, null)) {
if (e.getCapability(CapabilityKarma.KARMA_CAP, null).getKarma() < 1) {
e.addPotionEffect(new PotionEffect(Effects.snapEffect, random.nextInt((1200 - 10) + 1) - 10));
}
}
2019-06-08 12:49:20 +02:00
}
}
2019-05-14 18:30:44 +02:00
}
}
return false;
}
}