Add an entity blacklist for the Teleposer (#701)
Added event for when an entity is teleposed. Includes a Post version as well to allow modification of the entity after the fact.
This commit is contained in:
parent
cfce1a4a6c
commit
9253d6a410
|
@ -9,7 +9,6 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -23,6 +22,7 @@ public class ConfigHandler
|
||||||
// Teleposer
|
// Teleposer
|
||||||
public static String[] teleposerBlacklisting;
|
public static String[] teleposerBlacklisting;
|
||||||
public static ArrayList<BlockStack> teleposerBlacklist = new ArrayList<BlockStack>();
|
public static ArrayList<BlockStack> teleposerBlacklist = new ArrayList<BlockStack>();
|
||||||
|
public static List<String> teleposerBlacklistEntity;
|
||||||
|
|
||||||
// Transposition Sigil
|
// Transposition Sigil
|
||||||
public static String[] transpositionBlacklisting;
|
public static String[] transpositionBlacklisting;
|
||||||
|
@ -163,6 +163,7 @@ public class ConfigHandler
|
||||||
config.addCustomCategoryComment(category, "Block blacklisting");
|
config.addCustomCategoryComment(category, "Block blacklisting");
|
||||||
teleposerBlacklisting = config.getStringList("teleposerBlacklist", category, new String[] { "minecraft:bedrock", "minecraft:mob_spawner" }, "Stops specified blocks from being teleposed. Put entries on new lines. Valid syntax is:\nmodid:blockname:meta");
|
teleposerBlacklisting = config.getStringList("teleposerBlacklist", category, new String[] { "minecraft:bedrock", "minecraft:mob_spawner" }, "Stops specified blocks from being teleposed. Put entries on new lines. Valid syntax is:\nmodid:blockname:meta");
|
||||||
buildBlacklist(teleposerBlacklisting, teleposerBlacklist);
|
buildBlacklist(teleposerBlacklisting, teleposerBlacklist);
|
||||||
|
teleposerBlacklistEntity = Arrays.asList(config.getStringList("teleposerBlacklistEntity", category, new String[]{}, "Entity class names listed here will not be able to be teleposed."));
|
||||||
|
|
||||||
category = "Transposition Sigil Blacklist";
|
category = "Transposition Sigil Blacklist";
|
||||||
config.addCustomCategoryComment(category, "Block blacklisting");
|
config.addCustomCategoryComment(category, "Block blacklisting");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package WayofTime.bloodmagic.api.event;
|
package WayofTime.bloodmagic.api.event;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.BlockStack;
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -43,4 +44,43 @@ public class TeleposeEvent extends Event
|
||||||
{
|
{
|
||||||
return finalWorld.getTileEntity(finalBlockPos);
|
return finalWorld.getTileEntity(finalBlockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a Teleposer attempts to move an Entity between locations. Can be cancelled to
|
||||||
|
* stop transposition.
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public static class Ent extends TeleposeEvent
|
||||||
|
{
|
||||||
|
public final Entity entity;
|
||||||
|
|
||||||
|
public Ent(Entity entity, World initialWorld, BlockPos initialBlockPos, World finalWorld, BlockPos finalBlockPos)
|
||||||
|
{
|
||||||
|
super(initialWorld, initialBlockPos, finalWorld, finalBlockPos);
|
||||||
|
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity getInitialTile() throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Attempted to get a TileEntity from an Entity Telepose Event.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity getFinalTile() throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Attempted to get a TileEntity from an Entity Telepose Event.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after the entity has been transposed.
|
||||||
|
*/
|
||||||
|
public static class Post extends Ent {
|
||||||
|
|
||||||
|
public Post(Entity entity, World initialWorld, BlockPos initialBlockPos, World finalWorld, BlockPos finalBlockPos) {
|
||||||
|
super(entity, initialWorld, initialBlockPos, finalWorld, finalBlockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package WayofTime.bloodmagic.ritual.portal;
|
package WayofTime.bloodmagic.ritual.portal;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.event.TeleposeEvent;
|
||||||
import WayofTime.bloodmagic.api.network.SoulNetwork;
|
import WayofTime.bloodmagic.api.network.SoulNetwork;
|
||||||
import WayofTime.bloodmagic.api.teleport.Teleport;
|
import WayofTime.bloodmagic.api.teleport.Teleport;
|
||||||
import WayofTime.bloodmagic.api.teleport.TeleporterBloodMagic;
|
import WayofTime.bloodmagic.api.teleport.TeleporterBloodMagic;
|
||||||
|
@ -18,6 +19,8 @@ import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class Teleports
|
public class Teleports
|
||||||
|
@ -47,9 +50,11 @@ public class Teleports
|
||||||
{
|
{
|
||||||
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
||||||
if (network.getCurrentEssence() < getTeleportCost())
|
if (network.getCurrentEssence() < getTeleportCost())
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent(entity, entity.worldObj, entity.getPosition(), entity.worldObj, new BlockPos(x, y, z))))
|
||||||
|
return;
|
||||||
|
|
||||||
network.syphon(getTeleportCost());
|
network.syphon(getTeleportCost());
|
||||||
|
|
||||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||||
|
@ -60,13 +65,16 @@ public class Teleports
|
||||||
player.timeUntilPortal = 150;
|
player.timeUntilPortal = 150;
|
||||||
|
|
||||||
player.worldObj.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
player.worldObj.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
||||||
|
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.worldObj, entity.getPosition(), entity.worldObj, new BlockPos(x, y, z)));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
||||||
if (network.getCurrentEssence() < (getTeleportCost() / 10))
|
if (network.getCurrentEssence() < (getTeleportCost() / 10))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent(entity, entity.worldObj, entity.getPosition(), entity.worldObj, new BlockPos(x, y, z))))
|
||||||
|
return;
|
||||||
|
|
||||||
network.syphon(getTeleportCost() / 10);
|
network.syphon(getTeleportCost() / 10);
|
||||||
|
|
||||||
WorldServer world = (WorldServer) entity.worldObj;
|
WorldServer world = (WorldServer) entity.worldObj;
|
||||||
|
@ -76,6 +84,7 @@ public class Teleports
|
||||||
world.resetUpdateEntityTick();
|
world.resetUpdateEntityTick();
|
||||||
|
|
||||||
entity.worldObj.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
entity.worldObj.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
||||||
|
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.worldObj, entity.getPosition(), entity.worldObj, new BlockPos(x, y, z)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,9 +137,11 @@ public class Teleports
|
||||||
{
|
{
|
||||||
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
||||||
if (network.getCurrentEssence() < getTeleportCost())
|
if (network.getCurrentEssence() < getTeleportCost())
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent(entity, entity.worldObj, entity.getPosition(), newWorldServer, new BlockPos(x, y, z))))
|
||||||
|
return;
|
||||||
|
|
||||||
network.syphon(getTeleportCost());
|
network.syphon(getTeleportCost());
|
||||||
|
|
||||||
player.changeDimension(newWorldID); //TODO: UNTESTED
|
player.changeDimension(newWorldID); //TODO: UNTESTED
|
||||||
|
@ -138,15 +149,18 @@ public class Teleports
|
||||||
player.setPositionAndUpdate(x + 0.5, y + 0.5, z + 0.5);
|
player.setPositionAndUpdate(x + 0.5, y + 0.5, z + 0.5);
|
||||||
player.worldObj.updateEntityWithOptionalForce(player, false);
|
player.worldObj.updateEntityWithOptionalForce(player, false);
|
||||||
player.playerNetServerHandler.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
player.playerNetServerHandler.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
||||||
|
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.worldObj, entity.getPosition(), newWorldServer, new BlockPos(x, y, z)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!entity.worldObj.isRemote)
|
} else if (!entity.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain);
|
||||||
if (network.getCurrentEssence() < (getTeleportCost() / 10))
|
if (network.getCurrentEssence() < (getTeleportCost() / 10))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent(entity, entity.worldObj, entity.getPosition(), newWorldServer, new BlockPos(x, y, z))))
|
||||||
|
return;
|
||||||
|
|
||||||
network.syphon(getTeleportCost() / 10);
|
network.syphon(getTeleportCost() / 10);
|
||||||
|
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
@ -167,6 +181,7 @@ public class Teleports
|
||||||
|
|
||||||
oldWorldServer.resetUpdateEntityTick();
|
oldWorldServer.resetUpdateEntityTick();
|
||||||
newWorldServer.resetUpdateEntityTick();
|
newWorldServer.resetUpdateEntityTick();
|
||||||
|
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.worldObj, entity.getPosition(), newWorldServer, new BlockPos(x, y, z)));
|
||||||
}
|
}
|
||||||
entity.timeUntilPortal = entity instanceof EntityLiving ? 150 : 20;
|
entity.timeUntilPortal = entity instanceof EntityLiving ? 150 : 20;
|
||||||
newWorldServer.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
newWorldServer.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
||||||
|
|
|
@ -482,6 +482,17 @@ public class EventHandler
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onTeleposeEntity(TeleposeEvent.Ent event) {
|
||||||
|
if (ConfigHandler.teleposerBlacklistEntity.contains(event.entity.getClass().getSimpleName()))
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onTeleposeEntityPost(TeleposeEvent.Ent.Post event) {
|
||||||
|
event.entity.timeUntilPortal = 5;
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onConfigChanged(ConfigChangedEvent event)
|
public void onConfigChanged(ConfigChangedEvent event)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue