diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 14:54:57 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 14:54:57 +0000 |
commit | 228ddd39273b2ac38350764d29982519e27761c1 (patch) | |
tree | b288c8dcc17aa78eb7c84f9ef7853a4538f01e2f | |
parent | e7fb530caf15236026808ffaecaf1b2cae140776 (diff) | |
download | GT5-Unofficial-228ddd39273b2ac38350764d29982519e27761c1.tar.gz GT5-Unofficial-228ddd39273b2ac38350764d29982519e27761c1.tar.bz2 GT5-Unofficial-228ddd39273b2ac38350764d29982519e27761c1.zip |
Fixed Magic Feather death handling.
Improved Magic Feather beacon handling.
6 files changed, 268 insertions, 180 deletions
diff --git a/src/main/java/gtPlusPlus/core/common/CommonProxy.java b/src/main/java/gtPlusPlus/core/common/CommonProxy.java index fb3f291dd0..2909ef3541 100644 --- a/src/main/java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/main/java/gtPlusPlus/core/common/CommonProxy.java @@ -126,6 +126,8 @@ public class CommonProxy { Utils.registerEvent(new HandlerTooltip_GC()); // Handles Sleep Benefits PlayerSleepEventHandler.init(); + // Handles Magic Feather + Utils.registerEvent(ModItems.itemMagicFeather); if (CORE.DEVENV) { Utils.registerEvent(new StopAnnoyingFuckingAchievements()); diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index b9419a5ba6..c36344d805 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -1,7 +1,5 @@ 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.*; @@ -14,7 +12,6 @@ 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.minecraft.util.ChatComponentTranslation; diff --git a/src/main/java/gtPlusPlus/core/item/base/CoreItem.java b/src/main/java/gtPlusPlus/core/item/base/CoreItem.java index 7ce96b2a88..fbd04eb30b 100644 --- a/src/main/java/gtPlusPlus/core/item/base/CoreItem.java +++ b/src/main/java/gtPlusPlus/core/item/base/CoreItem.java @@ -140,7 +140,7 @@ public class CoreItem extends Item this.setMaxDamage(maxDmg); this.rarity = regRarity; this.itemDescription = description; - this.descColour = colour; + this.descColour = colour != null ? colour : EnumChatFormatting.RESET; this.hasEffect = Effect; this.turnsInto = OverrideItem; GameRegistry.registerItem(this, unlocalizedName); @@ -160,7 +160,7 @@ public class CoreItem extends Item this.setMaxDamage(maxDmg); this.rarity = regRarity; this.itemDescription = description; - this.descColour = colour; + this.descColour = colour != null ? colour : EnumChatFormatting.RESET; this.hasEffect = Effect; this.turnsInto = OverrideItem; GameRegistry.registerItem(this, unlocalizedName); diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java index 41b88b7aa8..4d34bf84e7 100644 --- a/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java +++ b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java @@ -1,17 +1,19 @@ package gtPlusPlus.core.item.general; -import java.util.List; -import java.util.WeakHashMap; +import java.util.*; +import cpw.mods.fml.common.eventhandler.EventPriority; 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.api.objects.Logger; 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.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.*; import net.minecraft.tileentity.TileEntity; @@ -19,178 +21,249 @@ import net.minecraft.tileentity.TileEntityBeacon; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingDeathEvent; 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 + public static final String NAME = "magicfeather"; + private static final WeakHashMap<UUID, MagicFeatherData> sPlayerData = new WeakHashMap<UUID, MagicFeatherData>(); + private static final WeakHashMap<UUID, HashSet<TileEntityBeacon>> sBeaconData = new WeakHashMap<UUID, HashSet<TileEntityBeacon>>(); + + public ItemMagicFeather() { + super("magicfeather", AddToCreativeTab.tabMisc, 1, 100, new String[]{"Lets you fly around Beacons"}, EnumRarity.uncommon, null, 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) { + list.add("Does not need to be the item held in your hand to work"); + super.addInformation(stack, aPlayer, list, bool); + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + list.add(""); + if (player != null) { + if (!isInBeaconRange(player)) { + list.add("" + EnumChatFormatting.RED + "Needs to be within beacon range"); + } + else { + list.add("" + EnumChatFormatting.GOLD + "Fly like an eagle"); + } + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.get(player.getUniqueID()); + if (aBeaconData != null && !aBeaconData.isEmpty()) { + list.add("Nearby Beacons:"); + for (TileEntityBeacon aBeacon : aBeaconData) { + int level = aBeacon.getLevels(); + if (level > 0) { + int radius = (level * 10 + 10); + int x = aBeacon.xCoord; + int z = aBeacon.zCoord; + int y = aBeacon.yCoord; + list.add("Level: "+level+", Radius: "+radius); + list.add("Location: "+x+", "+y+", "+z); + } + } + } + } + } + + public boolean hasCustomEntity(ItemStack stack) { + return true; + } + + private static boolean isInBeaconRange(EntityPlayer player) { + World world = player.getEntityWorld(); + if (world.isRemote) { + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.get(player.getUniqueID()); + if (aBeaconData != null) { + return !aBeaconData.isEmpty(); + } + return false; + } + List<TileEntity> tileEntities = world.loadedTileEntityList; + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.get(player.getUniqueID()); + if (aBeaconData == null) { + aBeaconData = new HashSet<TileEntityBeacon>(); + sBeaconData.put(player.getUniqueID(), aBeaconData); + } + for (TileEntity t : tileEntities) { + if (!(t instanceof TileEntityBeacon)) { + continue; + } + TileEntityBeacon beacon = (TileEntityBeacon) t; + int level = beacon.getLevels(); + if (level == 0) { + continue; + } + 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; + } + if (!aBeaconData.contains(beacon)) { + aBeaconData.add(beacon); + } + } + if (aBeaconData.size() > 0) { + 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(priority=EventPriority.HIGHEST) + public void onPlayerTick(TickEvent.PlayerTickEvent event) { + if (event.side != Side.SERVER) { + return; + } + EntityPlayer player = event.player; + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.get(player.getUniqueID()); + if (aBeaconData != null && !aBeaconData.isEmpty()) { + HashSet<TileEntityBeacon> aRemovals = new HashSet<TileEntityBeacon>(); + for (TileEntityBeacon aBeacon : aBeaconData) { + int level = aBeacon.getLevels(); + if (level == 0) { + aRemovals.add(aBeacon); + continue; + } + int radius = (level * 10 + 10); + int x = aBeacon.xCoord; + int z = aBeacon.zCoord; + if (player.posX < (x - radius) || player.posX > (x + radius)) { + aRemovals.add(aBeacon); + continue; + } + if (player.posZ < (z - radius) || player.posZ > (z + radius)) { + aRemovals.add(aBeacon); + continue; + } + } + aBeaconData.removeAll(aRemovals); + } + boolean hasItem = hasItem(player, ModItems.itemMagicFeather); + if (!hasItem) { + ItemMagicFeather.sPlayerData.remove(player.getUniqueID()); + } + MagicFeatherData data = ItemMagicFeather.sPlayerData.get(player.getUniqueID()); + if (data == null) { + data = new MagicFeatherData(player); + ItemMagicFeather.sPlayerData.put(player.getUniqueID(), data); + } + data.onTick(); + } + + @SubscribeEvent(priority=EventPriority.LOWEST) + public void onPlayerDeath(LivingDeathEvent event) { + if (event.entityLiving != null) { + EntityLivingBase aEntity = event.entityLiving; + if (aEntity instanceof EntityPlayer && aEntity.worldObj != null) { + if (aEntity.worldObj.isRemote) { + return; + } + else { + EntityPlayer aPlayer = (EntityPlayer) aEntity; + ItemMagicFeather.sPlayerData.remove(aPlayer.getUniqueID()); + ItemMagicFeather.sBeaconData.remove(aPlayer.getUniqueID()); + } + } + } + } + + private static boolean hasItem(EntityPlayer player, Item item) { + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (stack != null && stack.getItem() != null && stack.getItem() instanceof ItemMagicFeather) { + 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() { + try { + boolean hasItem = hasItem(player, ModItems.itemMagicFeather); + if (hasItem != this.hasItem) { + if (hasItem) { + this.onAdd(); + } + if (!hasItem) { + this.onRemove(); + } + this.hasItem = hasItem; + Logger.INFO("Ticking feather "+hasItem); + return; + } + } + catch (Throwable t) { + t.printStackTrace(); + } + + 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; + } + } + +} diff --git a/src/main/java/gtPlusPlus/core/recipe/RECIPES_General.java b/src/main/java/gtPlusPlus/core/recipe/RECIPES_General.java index d47b65391c..0482921c9a 100644 --- a/src/main/java/gtPlusPlus/core/recipe/RECIPES_General.java +++ b/src/main/java/gtPlusPlus/core/recipe/RECIPES_General.java @@ -329,6 +329,21 @@ public class RECIPES_General { ItemUtils.getItemStackFromFQRN("miscutils:SlowBuildingRing", 1), // Output 20 * 30, // Dur 16); // Eu + + // Magic Feather + CORE.RA.addSixSlotAssemblingRecipe( + new ItemStack[] { + ItemUtils.getSimpleStack(Items.feather, 64), + ItemUtils.getSimpleStack(Blocks.emerald_block, 32), + ItemUtils.getSimpleStack(Blocks.diamond_block, 32), + Materials.Ruby.getBlocks(32), + Materials.Sapphire.getBlocks(32), + ItemUtils.getSimpleStack(Blocks.gold_block, 32), + }, + Materials.Silver.getMolten(32 * 144), // Fluid + ItemUtils.getSimpleStack(ModItems.itemMagicFeather, 1), // Output + 20 * 120, // Dur + MaterialUtils.getVoltageForTier(4)); // Eu // Pest Killer CORE.RA.addSixSlotAssemblingRecipe( diff --git a/src/main/resources/assets/miscutils/lang/en_US.lang b/src/main/resources/assets/miscutils/lang/en_US.lang index 06b47f381e..c7d3e9a938 100644 --- a/src/main/resources/assets/miscutils/lang/en_US.lang +++ b/src/main/resources/assets/miscutils/lang/en_US.lang @@ -3374,4 +3374,5 @@ item.hydrogenchloridemix.name=Hydrogen Chlorine Mix sleep.event.okay=You slept well and now feel a little better. sleep.event.good=You slept well and now feel much better. sleep.event.wellrested=You feel really well rested. -sleep.event.downsides=The downsides of life no longer effect you.
\ No newline at end of file +sleep.event.downsides=The downsides of life no longer effect you. +item.miscutils:magicfeather.name=Magical Feather
\ No newline at end of file |