Add an event to control nether portal formation (#4735)

This commit is contained in:
Ben Staddon authored and LexManos committed 2018-05-16 22:48:14 -07:00
1 parent 36f94fd20e
commit 40b567e962
4 files changed
+77

No files matched your search

@@ -24,6 +24,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
@@ -740,6 +741,11 @@ public class ForgeEventFactory
return result == Result.DEFAULT ? def : result == Result.ALLOW;
}
public static boolean onTrySpawnPortal(World world, BlockPos pos, BlockPortal.Size size)
{
return MinecraftForge.EVENT_BUS.post(new BlockEvent.PortalSpawnEvent(world, pos, world.getBlockState(pos), size));
}
public static int onEnchantmentLevelSet(World world, BlockPos pos, int enchantRow, int power, ItemStack itemStack, int level)
{
net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent e = new net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent(world, pos, enchantRow, power, itemStack, level);
@@ -22,6 +22,7 @@ package net.minecraftforge.event.world;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
@@ -338,4 +339,27 @@ public class BlockEvent extends Event
}
}
}
/**
* Fired when an attempt is made to spawn a nether portal from
* {@link net.minecraft.block.BlockPortal#trySpawnPortal(World, BlockPos)}.
*
* If cancelled, the portal will not be spawned.
*/
@Cancelable
public static class PortalSpawnEvent extends BlockEvent
{
private final BlockPortal.Size size;
public PortalSpawnEvent(World world, BlockPos pos, IBlockState state, BlockPortal.Size size)
{
super(world, pos, state);
this.size = size;
}
public BlockPortal.Size getPortalSize()
{
return size;
}
}
}