Refactoring and cleanup
This commit is contained in:
@@ -4,6 +4,7 @@ import net.minecraft.entity.EntityLivingBase;
|
|||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.network.play.server.SPacketEntityEffect;
|
import net.minecraft.network.play.server.SPacketEntityEffect;
|
||||||
import net.minecraft.network.play.server.SPacketRemoveEntityEffect;
|
import net.minecraft.network.play.server.SPacketRemoveEntityEffect;
|
||||||
|
import net.minecraft.potion.PotionEffect;
|
||||||
import net.minecraftforge.event.entity.living.PotionEvent;
|
import net.minecraftforge.event.entity.living.PotionEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
@@ -51,31 +52,26 @@ public interface ISyncedPotion {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPotionExpiryEvent(PotionEvent.PotionExpiryEvent event){
|
public static void onPotionExpiryEvent(PotionEvent.PotionExpiryEvent event){
|
||||||
|
onPotionEffectEnd(event.getPotionEffect(), event.getEntityLiving());
|
||||||
if(event.getPotionEffect() != null && event.getPotionEffect().getPotion() instanceof ISyncedPotion
|
|
||||||
&& ((ISyncedPotion)event.getPotionEffect().getPotion()).shouldSync(event.getEntityLiving())){
|
|
||||||
|
|
||||||
if(!event.getEntityLiving().world.isRemote){
|
|
||||||
event.getEntityLiving().world.playerEntities.stream()
|
|
||||||
.filter(p -> p.getDistanceSq(event.getEntityLiving()) < SYNC_RADIUS * SYNC_RADIUS)
|
|
||||||
.forEach(p -> ((EntityPlayerMP)p).connection.sendPacket(new SPacketRemoveEntityEffect(
|
|
||||||
event.getEntity().getEntityId(), event.getPotionEffect().getPotion())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPotionRemoveEvent(PotionEvent.PotionRemoveEvent event){
|
public static void onPotionRemoveEvent(PotionEvent.PotionRemoveEvent event){
|
||||||
|
onPotionEffectEnd(event.getPotionEffect(), event.getEntityLiving());
|
||||||
|
}
|
||||||
|
|
||||||
if(event.getPotionEffect() != null && event.getPotionEffect().getPotion() instanceof ISyncedPotion
|
static void onPotionEffectEnd(PotionEffect effect, EntityLivingBase host){
|
||||||
&& ((ISyncedPotion)event.getPotionEffect().getPotion()).shouldSync(event.getEntityLiving())){
|
|
||||||
|
|
||||||
if(!event.getEntityLiving().world.isRemote){
|
if(effect != null && effect.getPotion() instanceof ISyncedPotion
|
||||||
event.getEntityLiving().world.playerEntities.stream()
|
&& ((ISyncedPotion)effect.getPotion()).shouldSync(host)){
|
||||||
.filter(p -> p.getDistanceSq(event.getEntityLiving()) < SYNC_RADIUS * SYNC_RADIUS)
|
|
||||||
|
if(!host.world.isRemote){
|
||||||
|
host.world.playerEntities.stream()
|
||||||
|
.filter(p -> p.getDistanceSq(host) < SYNC_RADIUS * SYNC_RADIUS)
|
||||||
.forEach(p -> ((EntityPlayerMP)p).connection.sendPacket(new SPacketRemoveEntityEffect(
|
.forEach(p -> ((EntityPlayerMP)p).connection.sendPacket(new SPacketRemoveEntityEffect(
|
||||||
event.getEntity().getEntityId(), event.getPotionEffect().getPotion())));
|
host.getEntityId(), effect.getPotion())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user