Added more Snap Abilities (WIP)

This commit is contained in:
Timo Ley 2019-05-14 18:30:44 +02:00
parent 0ba6efbeaf
commit 8f2d1a7b59
9 changed files with 200 additions and 26 deletions

View file

@ -0,0 +1,26 @@
package anvil.infinity.abilities;
import anvil.infinity.data.EntityData;
import anvil.infinity.data.GauntletUserInformation;
import lucraft.mods.lucraftcore.superpowers.abilities.AbilityAction;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
public class AbilityChangeSnap extends AbilityAction {
public AbilityChangeSnap(EntityLivingBase entity) {
super(entity);
}
@Override
public boolean action() {
EntityData data = GauntletUserInformation.getDataByEntity(entity);
data.selectedSnapResult = data.selectedSnapResult.next();
if (entity instanceof EntityPlayer) {
((EntityPlayer) entity).sendStatusMessage(new TextComponentString("Selected ability is: " + data.selectedSnapResult),true);
}
return true;
}
}

View file

@ -1,8 +1,11 @@
package anvil.infinity.abilities;
import anvil.infinity.compat.CompatHandler;
import anvil.infinity.data.GauntletUserInformation;
import anvil.infinity.helpers.GauntelHelper;
import anvil.infinity.registry.Effects;
import anvil.infinity.snap.SnapHelper;
import anvil.infinity.snap.SnapResult;
import lucraft.mods.lucraftcore.infinity.ModuleInfinity;
import lucraft.mods.lucraftcore.superpowers.abilities.AbilityAction;
import net.minecraft.client.Minecraft;
@ -15,6 +18,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
@ -28,7 +32,7 @@ import java.util.Random;
public class AbilitySnap extends AbilityAction {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
public AbilitySnap(EntityLivingBase entity) {
@ -37,31 +41,7 @@ public class AbilitySnap extends AbilityAction {
@Override
public boolean action() {
if (GauntelHelper.hasFullGauntlet(entity)) {
World w = entity.getEntityWorld();
List<Entity> entities = w.loadedEntityList;
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;
}
return false;
return SnapHelper.snap(entity);
}
@SideOnly(Side.CLIENT)

View file

@ -11,6 +11,8 @@ public class ConfigHandler {
public static boolean useSHRealityAbilities;
public static boolean sizeChanging;
public static float size;
public static int soulWorldID;
public static boolean snapCreative;
public static void refreshConfig(File file) {
config = new Configuration(file);
@ -27,6 +29,8 @@ public class ConfigHandler {
useSHRealityAbilities = config.getBoolean("SH Reality Stone abilities", category, false, "Should the Reality Stone have the abilities of the Speedster Heroes Reality Stone if it is installed");
sizeChanging = config.getBoolean("Size changing", category, true, "Should the Reality Stone be able to change the size");
size = config.getFloat("Size", category, 0.1f, 0.1f,10, "Which size should the Reality Stone change it's user to");
soulWorldID = config.getInt("Soul World ID", category, 10, -255, 255, "The ID of the Soul World Dimension");
snapCreative = config.getBoolean("Can Snap change Gamemode", category, false, "Can the Snap change the Gamemode to Creative");
}
}

View file

@ -0,0 +1,21 @@
package anvil.infinity.data;
import anvil.infinity.snap.SnapResult;
import net.minecraft.entity.EntityLivingBase;
public class EntityData {
public EntityLivingBase entity;
public int xPos;
public int yPos;
public int zPos;
public int dim;
public SnapResult selectedSnapResult;
public EntityData(EntityLivingBase entity) {
this.entity = entity;
selectedSnapResult = SnapResult.KILLHALF;
}
}

View file

@ -0,0 +1,23 @@
package anvil.infinity.data;
import net.minecraft.entity.EntityLivingBase;
import java.util.ArrayList;
import java.util.List;
public class GauntletUserInformation {
public static List<EntityData> gauntletUsers = new ArrayList<>();
public static EntityData getDataByEntity(EntityLivingBase entity) {
for (int i = 0; i < gauntletUsers.size(); i++) {
if (gauntletUsers.get(i).entity.equals(entity)) {
return gauntletUsers.get(i);
}
}
EntityData data = new EntityData(entity);
gauntletUsers.add(data);
return data;
}
}

View file

@ -1,5 +1,6 @@
package anvil.infinity.items;
import anvil.infinity.abilities.AbilityChangeSnap;
import anvil.infinity.abilities.AbilityHasMindStone;
import anvil.infinity.compat.CompatHandler;
import lucraft.mods.lucraftcore.infinity.EnumInfinityStone;
@ -35,6 +36,7 @@ public class ItemMindStone extends ItemInfinityStone {
public Ability.AbilityMap addStoneAbilities(EntityLivingBase entity, Ability.AbilityMap abilities, Ability.EnumAbilityContext context) {
abilities.put("flight", new AbilityFlight(entity).setDataValue(AbilityFlight.SPEED, 1f));
abilities.put("mind", new AbilityHasMindStone(entity));
abilities.put("changesnap", new AbilityChangeSnap(entity));
if (CompatHandler.isHeroesExpansion) {
abilities.put("telekinesis", CompatHandler.HeroesExpension.getAbilityGrabEntity(entity));
}

View file

@ -21,6 +21,7 @@ public class Abilities {
e.getRegistry().register(new AbilityEntry(AbilityHasSoulStone.class, new ResourceLocation(Infinity.MOD_ID, "soul")));
e.getRegistry().register(new AbilityEntry(AbilityHasTimeStone.class, new ResourceLocation(Infinity.MOD_ID, "time")));
e.getRegistry().register(new AbilityEntry(AbilityHasMindStone.class, new ResourceLocation(Infinity.MOD_ID, "mind")));
e.getRegistry().register(new AbilityEntry(AbilityChangeSnap.class, new ResourceLocation(Infinity.MOD_ID, "changesnap")));
}

View file

@ -0,0 +1,81 @@
package anvil.infinity.snap;
import anvil.infinity.config.ConfigHandler;
import anvil.infinity.data.GauntletUserInformation;
import anvil.infinity.helpers.GauntelHelper;
import anvil.infinity.registry.Effects;
import lucraft.mods.lucraftcore.infinity.ModuleInfinity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
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;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import java.util.List;
import java.util.Random;
public class SnapHelper {
static MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
public static boolean snap(EntityLivingBase entity) {
if (GauntelHelper.hasFullGauntlet(entity)) {
World w = entity.getEntityWorld();
if (GauntletUserInformation.getDataByEntity(entity).selectedSnapResult == SnapResult.KILLHALF) {
List<Entity> entities = w.loadedEntityList;
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;
} else if (GauntletUserInformation.getDataByEntity(entity).selectedSnapResult == SnapResult.DESTROYSTONES) {
entity.setHealth(1);
ItemStack gauntlet;
if (entity.getHeldItem(EnumHand.MAIN_HAND).getItem().equals(ModuleInfinity.INFINITY_GAUNTLET)) {
gauntlet = entity.getHeldItem(EnumHand.MAIN_HAND);
} else {
gauntlet = entity.getHeldItem(EnumHand.OFF_HAND);
}
} else if (GauntletUserInformation.getDataByEntity(entity).selectedSnapResult == SnapResult.CREATIVE) {
if (ConfigHandler.snapCreative) {
if (entity instanceof EntityPlayer) {
((EntityPlayer) entity).setGameType(GameType.CREATIVE);
return true;
}
}
} else if (GauntletUserInformation.getDataByEntity(entity).selectedSnapResult == SnapResult.BRINGBACK) {
} else if (GauntletUserInformation.getDataByEntity(entity).selectedSnapResult == SnapResult.RECREATE) {
}
}
return false;
}
}

View file

@ -0,0 +1,36 @@
package anvil.infinity.snap;
import anvil.infinity.config.ConfigHandler;
public enum SnapResult {
KILLHALF,
DESTROYSTONES,
BRINGBACK,
RECREATE,
CREATIVE;
public SnapResult next() {
switch(this) {
case KILLHALF: return DESTROYSTONES;
case DESTROYSTONES: return BRINGBACK;
case BRINGBACK: return RECREATE;
case RECREATE: if (ConfigHandler.snapCreative) {return CREATIVE;} else {return KILLHALF;}
case CREATIVE: return KILLHALF;
}
return KILLHALF;
}
@Override
public String toString() {
switch (this) {
case KILLHALF: return "Kill half";
case DESTROYSTONES: return "Destroy the Stones";
case BRINGBACK: return "Bring back the dusted";
case RECREATE: return "Recreate the Universe";
case CREATIVE: return "Change to Creative";
}
return "Kill half";
}
}