aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-29 13:07:43 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-29 13:07:43 +0000
commit143a76dd8b380f85dad4fee6359b5a17022feccb (patch)
tree53d6fef54ffd249a5b1d7f6a585ef590cac2e761 /src/main/java
parent9a25f7d7141def59ba11317a8ac4e3b2f72f24fd (diff)
downloadGT5-Unofficial-143a76dd8b380f85dad4fee6359b5a17022feccb.tar.gz
GT5-Unofficial-143a76dd8b380f85dad4fee6359b5a17022feccb.tar.bz2
GT5-Unofficial-143a76dd8b380f85dad4fee6359b5a17022feccb.zip
Added Mob Mentality.
Added perks to sleeping. Added Magic Feather.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/gtPlusPlus/GTplusplus.java4
-rw-r--r--src/main/java/gtPlusPlus/core/common/CommonProxy.java2
-rw-r--r--src/main/java/gtPlusPlus/core/handler/MobMentality.java58
-rw-r--r--src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java124
-rw-r--r--src/main/java/gtPlusPlus/core/item/ModItems.java9
-rw-r--r--src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java196
-rw-r--r--src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java11
-rw-r--r--src/main/java/gtPlusPlus/core/util/math/MathUtils.java13
-rw-r--r--src/main/java/gtPlusPlus/xmod/forestry/bees/items/output/GTPP_Propolis.java2
9 files changed, 414 insertions, 5 deletions
diff --git a/src/main/java/gtPlusPlus/GTplusplus.java b/src/main/java/gtPlusPlus/GTplusplus.java
index 1513a0999c..414eb10dae 100644
--- a/src/main/java/gtPlusPlus/GTplusplus.java
+++ b/src/main/java/gtPlusPlus/GTplusplus.java
@@ -28,8 +28,7 @@ import gtPlusPlus.core.commands.CommandEnableDebugWhileRunning;
import gtPlusPlus.core.commands.CommandMath;
import gtPlusPlus.core.common.CommonProxy;
import gtPlusPlus.core.config.ConfigHandler;
-import gtPlusPlus.core.handler.BookHandler;
-import gtPlusPlus.core.handler.PacketHandler;
+import gtPlusPlus.core.handler.*;
import gtPlusPlus.core.handler.Recipes.RegistrationHandler;
import gtPlusPlus.core.handler.events.BlockEventHandler;
import gtPlusPlus.core.handler.events.LoginEventHandler;
@@ -174,6 +173,7 @@ public class GTplusplus implements ActionListener {
Utils.registerEvent(new LoginEventHandler());
Utils.registerEvent(new MissingMappingsEvent());
+ Utils.registerEvent(new MobMentality());
Logger.INFO("Login Handler Initialized");
proxy.preInit(event);
diff --git a/src/main/java/gtPlusPlus/core/common/CommonProxy.java b/src/main/java/gtPlusPlus/core/common/CommonProxy.java
index c038afce8f..fb3f291dd0 100644
--- a/src/main/java/gtPlusPlus/core/common/CommonProxy.java
+++ b/src/main/java/gtPlusPlus/core/common/CommonProxy.java
@@ -124,6 +124,8 @@ public class CommonProxy {
Utils.registerEvent(new HandlerTooltip_EIO());
// Handles Custom Tooltips for GC
Utils.registerEvent(new HandlerTooltip_GC());
+ // Handles Sleep Benefits
+ PlayerSleepEventHandler.init();
if (CORE.DEVENV) {
Utils.registerEvent(new StopAnnoyingFuckingAchievements());
diff --git a/src/main/java/gtPlusPlus/core/handler/MobMentality.java b/src/main/java/gtPlusPlus/core/handler/MobMentality.java
new file mode 100644
index 0000000000..acc289fecd
--- /dev/null
+++ b/src/main/java/gtPlusPlus/core/handler/MobMentality.java
@@ -0,0 +1,58 @@
+package gtPlusPlus.core.handler;
+
+import java.util.*;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import gtPlusPlus.core.util.minecraft.EntityUtils;
+import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.monster.IMob;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraftforge.event.entity.living.LivingHurtEvent;
+
+public class MobMentality {
+
+ public static HashSet<Class<EntityLivingBase>> sIgnoredTypes = new HashSet<Class<EntityLivingBase>>();
+
+ @SubscribeEvent
+ public void onEntityDamaged(LivingHurtEvent event) {
+ final EntityLivingBase target = event.entityLiving;
+ for (Class<EntityLivingBase> aEntityClass : sIgnoredTypes) {
+ if (aEntityClass.isInstance(target)) {
+ return;
+ }
+ }
+ if (target instanceof EntityLivingBase) {
+ final EntityLivingBase entity = target;
+ final Entity attacker = event.source.getSourceOfDamage();
+ if (/*this.configuration.shouldIgnoreNeutralMobs() && */!(entity instanceof IMob)) {
+ return;
+ }
+ if (attacker == null) {
+ return;
+ }
+ if (attacker instanceof EntityLivingBase && !PlayerUtils.isRealPlayer((EntityLivingBase) attacker)) {
+ return;
+ }
+ if (attacker instanceof EntityPlayer && PlayerUtils.isCreative((EntityPlayer) attacker)) {
+ return;
+ }
+ if (attacker instanceof EntityLivingBase) {
+ List<Entity> aEntityList = target.worldObj.loadedEntityList;
+ List<EntityLivingBase> aRangedEntity = new ArrayList<EntityLivingBase>();
+ for (Entity aEntity : aEntityList) {
+ if (target.getClass().isInstance(aEntity)) {
+ if (EntityUtils.getDistance(target, aEntity) <= 32) {
+ aRangedEntity.add((EntityLivingBase) aEntity);
+ }
+ }
+ }
+ for (EntityLivingBase aEntity : aRangedEntity) {
+ aEntity.setRevengeTarget((EntityLivingBase) attacker);
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java
new file mode 100644
index 0000000000..d3700e1373
--- /dev/null
+++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java
@@ -0,0 +1,124 @@
+package gtPlusPlus.core.handler.events;
+
+import cpw.mods.fml.common.eventhandler.Event.Result;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.potion.GtPotionEffect;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.math.MathUtils;
+import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.potion.Potion;
+import net.minecraft.potion.PotionEffect;
+import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
+import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
+
+public class PlayerSleepEventHandler {
+
+ private static ArrayList<Potion> sPositiveEffects = new ArrayList<Potion>();
+ private static ArrayList<Potion> sNegativeEffects = new ArrayList<Potion>();
+
+ public static void init() {
+ Utils.registerEvent(new PlayerSleepEventHandler());
+ sPositiveEffects.add(Potion.moveSpeed);
+ sPositiveEffects.add(Potion.waterBreathing);
+ sPositiveEffects.add(Potion.resistance);
+ sPositiveEffects.add(Potion.regeneration);
+ sPositiveEffects.add(Potion.damageBoost);
+ sPositiveEffects.add(Potion.digSpeed);
+ sPositiveEffects.add(Potion.fireResistance);
+ sPositiveEffects.add(Potion.field_76434_w); // Health Boost
+ sPositiveEffects.add(Potion.field_76444_x); // Absorption
+ sNegativeEffects.add(Potion.blindness);
+ sNegativeEffects.add(Potion.confusion);
+ sNegativeEffects.add(Potion.digSlowdown);
+ sNegativeEffects.add(Potion.harm);
+ sNegativeEffects.add(Potion.hunger);
+ sNegativeEffects.add(Potion.moveSlowdown);
+ sNegativeEffects.add(Potion.poison);
+ sNegativeEffects.add(Potion.weakness);
+ sNegativeEffects.add(Potion.wither);
+ }
+
+ @SubscribeEvent
+ public void sleep(PlayerSleepInBedEvent event) {
+ event.setResult(Result.ALLOW);
+ }
+
+ @SubscribeEvent
+ public void wake(PlayerWakeUpEvent event) {
+ EntityPlayer aPlayer = event.entityPlayer;
+ if (aPlayer != null && !aPlayer.worldObj.isRemote) {
+ // Try Heal
+ float aCurrentHP = aPlayer.getHealth();
+ float aMaxHP = aPlayer.getMaxHealth();
+ if (aCurrentHP < aMaxHP) {
+ float aDamage = aMaxHP - aCurrentHP;
+ float aToHeal = MathUtils.randFloat(1, aDamage);
+ if (aToHeal > 0) {
+ aPlayer.heal(aToHeal);
+ PlayerUtils.messagePlayer(aPlayer, "You slept well and now feel " + (aToHeal >= aDamage / 2 ? "much" : "a little") + " better.");
+ }
+ }
+ // Already healed, try give a buff
+ else {
+ int aRandomBuff = MathUtils.randInt(0, sPositiveEffects.size() - 1);
+ Potion aPotionToApply = sPositiveEffects.get(aRandomBuff);
+ if (aPotionToApply != null) {
+ aPlayer.addPotionEffect(new GtPotionEffect(aPotionToApply.id, MathUtils.randInt(60, 180), MathUtils.randInt(0, 2)));
+ PlayerUtils.messagePlayer(aPlayer, "You feel really well rested.");
+ }
+ }
+ boolean aRemovedBad = false;
+ /*for (Potion aBadPotion : sNegativeEffects) {
+ if (curePotionEffect(aPlayer, aBadPotion)) {
+ aRemovedBad = true;
+ }
+ }*/
+ if (aRemovedBad) {
+ PlayerUtils.messagePlayer(aPlayer, "The downsides of life no longer effect you.");
+ }
+ }
+ }
+
+ private static Field sActivePotionEffects = ReflectionUtils.getField(EntityPlayer.class, "activePotionsMap");
+ private static Method sOnFinishedPotionEffect = ReflectionUtils.getMethod(EntityPlayer.class, "onFinishedPotionEffect", PotionEffect.class);
+
+ public boolean curePotionEffect(EntityPlayer aPlayer, Potion aPotion) {
+ HashMap activePotionsMap = new HashMap();
+ try {
+ activePotionsMap = ReflectionUtils.getFieldValue(sActivePotionEffects, aPlayer);
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
+ if (aPlayer != null && aPotion != null && activePotionsMap != null && activePotionsMap.size() > 0) {
+ Iterator<Integer> potionKey = activePotionsMap.keySet().iterator();
+ if (!aPlayer.worldObj.isRemote) {
+ while (potionKey.hasNext()) {
+ try {
+ Integer key = potionKey.next();
+ PotionEffect effect = (PotionEffect) activePotionsMap.get(key);
+ if (effect.getPotionID() == aPotion.getId()) {
+ potionKey.remove();
+ ReflectionUtils.invokeVoid(aPlayer, sOnFinishedPotionEffect, new Object[]{effect});
+ return true;
+ }
+ }
+ catch (ConcurrentModificationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/gtPlusPlus/core/item/ModItems.java b/src/main/java/gtPlusPlus/core/item/ModItems.java
index cf70c56f21..7342c55939 100644
--- a/src/main/java/gtPlusPlus/core/item/ModItems.java
+++ b/src/main/java/gtPlusPlus/core/item/ModItems.java
@@ -76,11 +76,13 @@ import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechItems;
import net.minecraft.item.*;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
public final class ModItems {
+
public static ToolMaterial STABALLOY = EnumHelper.addToolMaterial("Staballoy", 3, 2500, 7, 1.0F, 18);
public static Item ZZZ_Empty;
@@ -355,6 +357,8 @@ public final class ModItems {
public static CoreItem itemExquisiteIndustrialDiamond;
public static BaseItemMetaFood itemMetaFood;
+
+ public static ItemMagicFeather itemMagicFeather;
static {
Logger.INFO("Items!");
@@ -365,8 +369,9 @@ public final class ModItems {
public static final void init(){
- itemDebugScanner = new DebugScanner();
-
+ itemDebugScanner = new DebugScanner();
+ itemMagicFeather = new ItemMagicFeather();
+
itemAlkalusDisk = new BaseItemDamageable("itemAlkalusDisk", AddToCreativeTab.tabMisc, 1, 0, "Unknown Use", EnumRarity.rare, EnumChatFormatting.AQUA, false, null);
itemBigEgg = new ItemGiantEgg();
itemGenericToken = new ItemGenericToken();
diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java
new file mode 100644
index 0000000000..41b88b7aa8
--- /dev/null
+++ b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java
@@ -0,0 +1,196 @@
+package gtPlusPlus.core.item.general;
+
+import java.util.List;
+import java.util.WeakHashMap;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.gameevent.TickEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import gtPlusPlus.core.creative.AddToCreativeTab;
+import gtPlusPlus.core.item.ModItems;
+import gtPlusPlus.core.item.base.CoreItem;
+import gtPlusPlus.core.lib.CORE;
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.*;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.tileentity.TileEntityBeacon;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.world.World;
+import net.minecraftforge.common.MinecraftForge;
+
+public class ItemMagicFeather extends CoreItem {
+
+ public static final String NAME = "magicfeather";
+ private static final WeakHashMap<EntityPlayer, MagicFeatherData> playerData = new WeakHashMap<>();
+
+ public ItemMagicFeather() {
+ super("magicfeather", AddToCreativeTab.tabMisc, 1, 100, new String[] {"Lets you fly around Beacons"}, EnumRarity.rare, EnumChatFormatting.BOLD, false, null);
+ setMaxStackSize(1);
+ setUnlocalizedName(CORE.MODID + ":" + NAME);
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @Override
+ public int getEntityLifespan(ItemStack itemStack, World world) {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) {
+ super.addInformation(stack, aPlayer, list, bool);
+ EntityPlayer player = Minecraft.getMinecraft().thePlayer;
+ if (player != null) {
+ if (!isInBeaconRange(player)) {
+ list.add(""+EnumChatFormatting.RED+"Needs to be within beacon range");
+ }
+ }
+ }
+
+ public boolean hasCustomEntity(ItemStack stack) {
+ return true;
+ }
+
+ private static boolean isInBeaconRange(EntityPlayer player) {
+ World world = player.getEntityWorld();
+
+ List<TileEntity> tileEntities = world.loadedTileEntityList;
+ for (TileEntity t : tileEntities) {
+ if (!(t instanceof TileEntityBeacon)) {
+ continue;
+ }
+
+ TileEntityBeacon beacon = (TileEntityBeacon) t;
+
+ int level = beacon.getLevels();
+ int radius = (level * 10 + 10);
+
+ int x = beacon.xCoord;
+ int z = beacon.zCoord;;
+
+ if (player.posX < (x - radius) || player.posX > (x + radius)) {
+ continue;
+ }
+
+ if (player.posZ < (z - radius) || player.posZ > (z + radius)) {
+ continue;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private static void setMayFly(EntityPlayer player, boolean mayFly) {
+ if (player.capabilities.allowFlying == mayFly) {
+ return;
+ }
+
+ if (!mayFly) {
+ // force the player on the ground then remove ability to fly
+ // this prevent crashing the the ground and dying
+ // when you accidentally get out of the beacon range
+ player.capabilities.isFlying = false;
+
+ if (player.onGround && player.fallDistance < 1F) {
+ player.capabilities.allowFlying = false;
+ }
+ } else {
+ player.capabilities.allowFlying = true;
+ }
+
+ player.sendPlayerAbilities();
+ }
+
+ @SubscribeEvent
+ public void onPlayerTick(TickEvent.PlayerTickEvent event) {
+ if (event.side != Side.SERVER) {
+ return;
+ }
+
+ EntityPlayer player = event.player;
+
+ MagicFeatherData data = ItemMagicFeather.playerData.get(player);
+ if (data == null) {
+ data = new MagicFeatherData(player);
+ ItemMagicFeather.playerData.put(player, data);
+ }
+
+ data.onTick();
+ }
+
+ private static boolean hasItem(EntityPlayer player, Item item) {
+ for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
+ ItemStack stack = player.inventory.getStackInSlot(i);
+ if (item == stack.getItem()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static class MagicFeatherData {
+ private final EntityPlayer player;
+ private boolean hasItem = false;
+
+ private int checkTick = 0;
+ private boolean beaconInRangeCache;
+
+ public MagicFeatherData(EntityPlayer player) {
+ this.player = player;
+ this.beaconInRangeCache = player.capabilities.allowFlying;
+ }
+
+ public void onTick() {
+
+ boolean hasItem = hasItem(player, ModItems.itemMagicFeather);
+ if (hasItem != this.hasItem) {
+ if (hasItem) {
+ this.onAdd();
+ }
+
+ if (!hasItem) {
+ this.onRemove();
+ }
+
+ this.hasItem = hasItem;
+ return;
+ }
+
+ boolean mayFly = player.capabilities.isCreativeMode || (hasItem && checkBeaconInRange(player));
+ setMayFly(player, mayFly);
+ }
+
+ private void onAdd() {
+ if (!ItemMagicFeather.isInBeaconRange(player)) {
+ return;
+ }
+
+ setMayFly(player, true);
+ }
+
+ private void onRemove() {
+ if (player.capabilities.isCreativeMode) {
+ return;
+ }
+
+ setMayFly(player, false);
+ }
+
+ private boolean checkBeaconInRange(EntityPlayer player) {
+
+ if (checkTick++ % 40 != 0) {
+ return beaconInRangeCache;
+ }
+
+ beaconInRangeCache = ItemMagicFeather.isInBeaconRange(player);
+
+ return beaconInRangeCache;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java b/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java
new file mode 100644
index 0000000000..fa31f68389
--- /dev/null
+++ b/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java
@@ -0,0 +1,11 @@
+package gtPlusPlus.core.potion;
+
+import net.minecraft.potion.PotionEffect;
+
+public class GtPotionEffect extends PotionEffect {
+
+ public GtPotionEffect(int aPotionID, int aDurationInSecs, int aLevel) {
+ super(aPotionID, aDurationInSecs * 20, aLevel, false);
+ }
+
+}
diff --git a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java
index 7573e0d51c..ef5db6e4e0 100644
--- a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java
+++ b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java
@@ -135,6 +135,19 @@ public class MathUtils {
public static double findPercentage(final double current, final double max){
return Math.round(((current / max) * 100) * 100.00) / 100.00;
}
+
+ /**
+ * Returns a percentage.
+ * The returned number is the % of X in Y.
+ * Supports Floats.
+ *
+ * @param current Current value.
+ * @param max Maximim value. Must be greater than min.
+ * @return double between min and max, inclusive.
+ */
+ public static float findPercentage(final float current, final float max){
+ return (float) (Math.round(((current / max) * 100) * 100.00) / 100.00);
+ }
public static int findPercentageOfInt(long input, float percentage){
return (int)(input*(percentage/100.0f));
diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/items/output/GTPP_Propolis.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/items/output/GTPP_Propolis.java
index d1cf088d39..fef721839b 100644
--- a/src/main/java/gtPlusPlus/xmod/forestry/bees/items/output/GTPP_Propolis.java
+++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/items/output/GTPP_Propolis.java
@@ -76,7 +76,7 @@ public class GTPP_Propolis extends Item {
Logger.BEES("Processing recipes for "+GTPP_Bees.sPropolisMappings.size()+" Propolis.");
for (GTPP_PropolisType aProp : GTPP_Bees.sPropolisMappings.values()) {
tDrop = aProp.getStackForType(1);
- if (addProcess(tDrop, aProp.mMaterial.getDust(1), (int) Math.min(Math.max(10000-(aProp.mMaterial.vTier*625), 100) / 10, 10000), aProp.mMaterial.vTier * 20 * 15, aProp.mMaterial.vVoltageMultiplier)) {
+ if (addProcess(tDrop, aProp.mMaterial.getDust(1), Math.min(Math.max(10000-(aProp.mMaterial.vTier*625), 100), 10000), aProp.mMaterial.vTier * 20 * 15, aProp.mMaterial.vVoltageMultiplier)) {
Logger.BEES("Added Propolis extraction recipe for: "+aProp.getName());
}
else {