Skip to content

Commit

Permalink
PotionCore Jump Ordering and Fixes
Browse files Browse the repository at this point in the history
Run potion core jump handling runs before other events
Also fix issues with invalid jump boosts
  • Loading branch information
Charles445 committed Feb 19, 2022
1 parent ad3dac4 commit ae41275
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12.2-0.5.0"
version = "1.12.2-0.5.1"
group = "com.charles445.rltweaker" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "RLTweaker"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/charles445/rltweaker/RLTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class RLTweaker
{
public static final String MODID = "rltweaker";
public static final String NAME = "RLTweaker";
public static final String VERSION = "0.5.0";
public static final String VERSION = "0.5.1";
public static final VersionDelimiter VERSION_DELIMITER = new VersionDelimiter(VERSION);

@Mod.Instance(RLTweaker.MODID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
import com.charles445.rltweaker.util.ErrorUtil;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.living.PotionEvent.PotionApplicableEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.IEventListener;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class PotionCoreHandler
{
Expand Down Expand Up @@ -48,7 +54,8 @@ public PCJump(IEventListener handler)
MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent
//Running late will override other jump events
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onJump(LivingEvent.LivingJumpEvent event)
{
EntityLivingBase living = event.getEntityLiving();
Expand All @@ -59,11 +66,79 @@ public void onJump(LivingEvent.LivingJumpEvent event)
if (jumpEffect != null && (jumpEffect.getAmplifier() < 0 || jumpEffect.getAmplifier() > 127))
{
if(living.world.isRemote)
{
living.getEntityData().setBoolean("Potion Core - Jump Boost Jumping", false);
}

return;
}

handler.invoke(event);

//Clean up jump effect on client if necessary
if(jumpEffect == null && living.world.isRemote)
{
living.getEntityData().setBoolean("Potion Core - Jump Boost Jumping", false);
}
}

@SubscribeEvent
public void onPlayerUpdate(PlayerTickEvent event)
{
if(event.phase == TickEvent.Phase.END)
return;

EntityPlayer player = event.player;

if(player == null)
return;

World world = player.world;

if(world == null)
return;

if(!world.isRemote)
return;

double jbh = event.player.getEntityData().getDouble("Potion Core - Jump Boost Height");

if(jbh > 127)
{
ErrorUtil.logSilent("PotionCore Invalid Jump Boost Height");
event.player.getEntityData().setDouble("Potion Core - Jump Boost Height", 1.75D);
}
}

@SubscribeEvent
public void potionApplicable(PotionApplicableEvent event)
{
EntityLivingBase living = event.getEntityLiving();
PotionEffect newEffect = event.getPotionEffect();

if(newEffect == null)
return;

if(!(living instanceof EntityPlayer))
return;

if(!living.world.isRemote)
return;

//Client only

if(newEffect.getPotion() == MobEffects.JUMP_BOOST)
{
PotionEffect oldEffect = living.getActivePotionEffect(MobEffects.JUMP_BOOST);
if(oldEffect == null)
return;

if(newEffect.getAmplifier() < 0 && oldEffect.getAmplifier() >= 0)
{
//Got sent a negative number from server, remove the potion effect to let it through
living.removePotionEffect(MobEffects.JUMP_BOOST);
}
}
}
}
}

0 comments on commit ae41275

Please sign in to comment.