diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 459b69865d4..4e8bea74818 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -46,12 +46,13 @@ public enum Mixin { .setApplyIf(() -> ConfigHandler.enabledPatches[3]) .setPhase(Phase.EARLY) .setSide(Side.BOTH)), - CraftingRecipeAccessorMixin(new Builder("Add accessors to crafting recipe types") + VanillaAccessors(new Builder("Adds various accessors") .addMixinClasses( "minecraft.VanillaShapedRecipeMixin", "minecraft.VanillaShapelessRecipeMixin", "minecraft.ForgeShapedRecipeMixin", - "minecraft.ForgeShapelessRecipeMixin") + "minecraft.ForgeShapelessRecipeMixin", + "minecraft.PotionMixin") .addTargetedMod(VANILLA) .setApplyIf(() -> true) .setPhase(Phase.EARLY) diff --git a/src/main/java/kubatech/api/IBlockStemAccesor.java b/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java similarity index 74% rename from src/main/java/kubatech/api/IBlockStemAccesor.java rename to src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java index 8f2c37e15fe..089479f8ad9 100644 --- a/src/main/java/kubatech/api/IBlockStemAccesor.java +++ b/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java @@ -1,4 +1,4 @@ -package kubatech.api; +package gregtech.mixin.interfaces; import net.minecraft.block.Block; diff --git a/src/main/java/gregtech/mixin/interfaces/PotionExt.java b/src/main/java/gregtech/mixin/interfaces/PotionExt.java new file mode 100644 index 00000000000..11ae365e5a9 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/PotionExt.java @@ -0,0 +1,7 @@ +package gregtech.mixin.interfaces; + +public interface PotionExt { + + boolean gt5u$isBadEffect(); + +} diff --git a/src/main/java/gtPlusPlus/core/common/CommonProxy.java b/src/main/java/gtPlusPlus/core/common/CommonProxy.java index 8de034148bf..066dacdd9c6 100644 --- a/src/main/java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/main/java/gtPlusPlus/core/common/CommonProxy.java @@ -56,12 +56,10 @@ public CommonProxy() { public void preInit(final FMLPreInitializationEvent e) { Logger.INFO("Doing some house cleaning."); - if (!PreloaderCore.DEBUG_MODE) { - Logger.WARNING("Development mode not enabled."); - } else if (PreloaderCore.DEBUG_MODE) { + if (PreloaderCore.DEBUG_MODE) { Logger.INFO("Development mode enabled."); } else { - Logger.WARNING("Development mode not set."); + Logger.WARNING("Development mode not enabled."); } AddToCreativeTab.initialiseTabs(); diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index b01d9d6190d..33649b4ff28 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -1,109 +1,77 @@ package gtPlusPlus.core.handler.events; -import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collection; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentTranslation; -import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.potion.GtPotionEffect; -import gtPlusPlus.core.util.Utils; +import gregtech.mixin.interfaces.PotionExt; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.preloader.PreloaderCore; public class PlayerSleepEventHandler { - private static Field sEffectDuration = ReflectionUtils - .getField(PotionEffect.class, !PreloaderCore.DEV_ENVIRONMENT ? "field_76460_b" : "duration"); - private static ArrayList sPositiveEffects = new ArrayList<>(); - private static ArrayList sNegativeEffects = new ArrayList<>(); + private static final ArrayList potionBuffs = new ArrayList<>(); 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); + MinecraftForge.EVENT_BUS.register(new PlayerSleepEventHandler()); + potionBuffs.add(Potion.moveSpeed); + potionBuffs.add(Potion.waterBreathing); + potionBuffs.add(Potion.resistance); + potionBuffs.add(Potion.regeneration); + potionBuffs.add(Potion.damageBoost); + potionBuffs.add(Potion.digSpeed); + potionBuffs.add(Potion.fireResistance); + potionBuffs.add(Potion.field_76434_w); // Health Boost + potionBuffs.add(Potion.field_76444_x); // Absorption + potionBuffs.trimToSize(); } @SubscribeEvent - public void sleep(PlayerSleepInBedEvent event) {} - - @SubscribeEvent - public void wake(PlayerWakeUpEvent event) { - EntityPlayer aPlayer = event.entityPlayer; - if (aPlayer != null && !aPlayer.worldObj.isRemote) { - if (event.entityPlayer.getEntityWorld() - .getWorldTime() % 24000 != 0) { - return; - } - boolean aRemovedBad = false; - try { - Collection aActive = aPlayer.getActivePotionEffects(); - for (PotionEffect aEffect : aActive) { - for (Potion aBadPotion : sNegativeEffects) { - if (aEffect.getPotionID() == aBadPotion.getId()) { - ReflectionUtils.setField(aEffect, sEffectDuration, 1); - aRemovedBad = true; - Logger.INFO("Set duration of " + aEffect.getEffectName() + " to 1 tick"); - } - } - } - } catch (Throwable t) { - t.printStackTrace(); - } - if (aRemovedBad) { - messagePlayer(aPlayer, "sleep.event.downsides"); - } else { - // 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); - messagePlayer(aPlayer, (aToHeal >= aDamage / 2 ? "sleep.event.good" : "sleep.event.okay")); - } - } - // 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))); - messagePlayer(aPlayer, "sleep.event.wellrested"); - } - } + public void onPlayerWakeUp(PlayerWakeUpEvent event) { + EntityPlayer player = event.entityPlayer; + if (player == null || player.worldObj.isRemote) return; + if (player.getEntityWorld() + .getWorldTime() % 24000 != 0) { + return; + } + final List potionToRemove = new ArrayList<>(); + for (PotionEffect potionEffect : player.getActivePotionEffects()) { + final Potion potion = Potion.potionTypes[potionEffect.getPotionID()]; + if (potion instanceof PotionExt && ((PotionExt) potion).gt5u$isBadEffect()) { + potionToRemove.add(potion.id); } } + for (Integer i : potionToRemove) { + player.removePotionEffect(i); + } + if (!potionToRemove.isEmpty()) { + messagePlayer(player, "sleep.event.downsides"); + return; + } + // Try Heal + float currentHP = player.getHealth(); + float maxHP = player.getMaxHealth(); + if (currentHP < maxHP) { + float missingHP = maxHP - currentHP; + float heal = MathUtils.randFloat(1, missingHP); + player.heal(heal); + messagePlayer(player, (heal >= missingHP / 2 ? "sleep.event.good" : "sleep.event.okay")); + return; + } + // Try give a buff + Potion aPotionToApply = potionBuffs.get(MathUtils.randInt(0, potionBuffs.size() - 1)); + player.addPotionEffect( + new PotionEffect(aPotionToApply.id, MathUtils.randInt(60, 180) * 20, MathUtils.randInt(0, 2))); + messagePlayer(player, "sleep.event.wellrested"); } - private static void messagePlayer(EntityPlayer aPlayer, String aChatKey) { - PlayerUtils.messagePlayer(aPlayer, new ChatComponentTranslation(aChatKey, new Object[0])); + private static void messagePlayer(EntityPlayer player, String aChatKey) { + player.addChatComponentMessage(new ChatComponentTranslation(aChatKey)); } } diff --git a/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java b/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java deleted file mode 100644 index 65e7d20af08..00000000000 --- a/src/main/java/gtPlusPlus/core/potion/GtPotionEffect.java +++ /dev/null @@ -1,10 +0,0 @@ -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/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGStemBucket.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGStemBucket.java index b132243a667..76ba7620c6f 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGStemBucket.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGStemBucket.java @@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.IPlantable; -import kubatech.api.IBlockStemAccesor; +import gregtech.mixin.interfaces.IBlockStemAccesor; import kubatech.api.eig.EIGBucket; import kubatech.api.eig.EIGDropTable; import kubatech.api.eig.IEIGBucketFactory; diff --git a/src/mixin/java/gregtech/mixin/mixins/early/minecraft/BlockStemMixin.java b/src/mixin/java/gregtech/mixin/mixins/early/minecraft/BlockStemMixin.java index 685e00b2a89..146c527d029 100644 --- a/src/mixin/java/gregtech/mixin/mixins/early/minecraft/BlockStemMixin.java +++ b/src/mixin/java/gregtech/mixin/mixins/early/minecraft/BlockStemMixin.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import kubatech.api.IBlockStemAccesor; +import gregtech.mixin.interfaces.IBlockStemAccesor; @Mixin(value = BlockStem.class) public class BlockStemMixin implements IBlockStemAccesor { diff --git a/src/mixin/java/gregtech/mixin/mixins/early/minecraft/PotionMixin.java b/src/mixin/java/gregtech/mixin/mixins/early/minecraft/PotionMixin.java new file mode 100644 index 00000000000..94b11af492b --- /dev/null +++ b/src/mixin/java/gregtech/mixin/mixins/early/minecraft/PotionMixin.java @@ -0,0 +1,23 @@ +package gregtech.mixin.mixins.early.minecraft; + +import net.minecraft.potion.Potion; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import gregtech.mixin.interfaces.PotionExt; + +@Mixin(Potion.class) +public class PotionMixin implements PotionExt { + + @Shadow + @Final + private boolean isBadEffect; + + @Override + public boolean gt5u$isBadEffect() { + return this.isBadEffect; + } + +}