Search in sources :

Example 1 with TileEntityCageTrap

use of net.geforcemods.securitycraft.tileentity.TileEntityCageTrap in project SecurityCraft by Geforce132.

the class BlockCageTrap method onEntityIntersected.

@Override
public void onEntityIntersected(World world, BlockPos pos, Entity entity) {
    if (!world.isRemote) {
        TileEntityCageTrap tileEntity = (TileEntityCageTrap) world.getTileEntity(pos);
        boolean isPlayer = entity instanceof EntityPlayer;
        boolean shouldCaptureMobs = tileEntity.getOptionByName("captureMobs").asBoolean();
        if (isPlayer || (entity instanceof EntityMob && shouldCaptureMobs)) {
            if ((isPlayer && ((IOwnable) world.getTileEntity(pos)).getOwner().isOwner((EntityPlayer) entity)))
                return;
            if (BlockUtils.getBlockPropertyAsBoolean(world, pos, DEACTIVATED))
                return;
            BlockUtils.setBlockProperty(world, pos, DEACTIVATED, true);
            BlockUtils.setBlock(world, pos.up(4), SCContent.unbreakableIronBars);
            BlockUtils.setBlock(world, pos.getX() + 1, pos.getY() + 4, pos.getZ(), SCContent.unbreakableIronBars);
            BlockUtils.setBlock(world, pos.getX() - 1, pos.getY() + 4, pos.getZ(), SCContent.unbreakableIronBars);
            BlockUtils.setBlock(world, pos.getX(), pos.getY() + 4, pos.getZ() + 1, SCContent.unbreakableIronBars);
            BlockUtils.setBlock(world, pos.getX(), pos.getY() + 4, pos.getZ() - 1, SCContent.unbreakableIronBars);
            BlockUtils.setBlockInBox(world, pos.getX(), pos.getY(), pos.getZ(), SCContent.unbreakableIronBars);
            setTileEntities(world, pos.getX(), pos.getY(), pos.getZ(), ((IOwnable) world.getTileEntity(pos)).getOwner().getUUID(), ((IOwnable) world.getTileEntity(pos)).getOwner().getName());
            world.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "random.anvil_use", 3.0F, 1.0F);
            if (isPlayer)
                MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentTranslation("[" + EnumChatFormatting.BLACK + StatCollector.translateToLocal("tile.cageTrap.name") + EnumChatFormatting.RESET + "] " + StatCollector.translateToLocal("messages.cageTrap.captured").replace("#player", ((EntityPlayer) entity).getCommandSenderName()).replace("#location", Utils.getFormattedCoordinates(pos))));
        }
    }
}
Also used : TileEntityCageTrap(net.geforcemods.securitycraft.tileentity.TileEntityCageTrap) EntityMob(net.minecraft.entity.monster.EntityMob) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Example 2 with TileEntityCageTrap

use of net.geforcemods.securitycraft.tileentity.TileEntityCageTrap in project SecurityCraft by Geforce132.

the class BlockCageTrap method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
    if (!par1World.isRemote) {
        TileEntityCageTrap tileEntity = (TileEntityCageTrap) par1World.getTileEntity(par2, par3, par4);
        boolean isPlayer = par5Entity instanceof EntityPlayer;
        boolean shouldCaptureMobs = tileEntity.getOptionByName("captureMobs").asBoolean();
        if ((isPlayer || par5Entity instanceof EntityMob) && !deactivated) {
            IOwnable originalTrap = (IOwnable) par1World.getTileEntity(par2, par3, par4);
            if (isPlayer && originalTrap.getOwner().isOwner((EntityPlayer) par5Entity))
                return;
            if (!isPlayer && !shouldCaptureMobs)
                return;
            par1World.setBlock(par2, par3, par4, SCContent.deactivatedCageTrap);
            par1World.setBlock(par2, par3 + 4, par4, SCContent.unbreakableIronBars);
            par1World.setBlock(par2 + 1, par3 + 4, par4, SCContent.unbreakableIronBars);
            par1World.setBlock(par2 - 1, par3 + 4, par4, SCContent.unbreakableIronBars);
            par1World.setBlock(par2, par3 + 4, par4 + 1, SCContent.unbreakableIronBars);
            par1World.setBlock(par2, par3 + 4, par4 - 1, SCContent.unbreakableIronBars);
            BlockUtils.setBlockInBox(par1World, par2, par3, par4, SCContent.unbreakableIronBars);
            setTileEntities(par1World, par2, par3, par4, originalTrap.getOwner().getUUID(), originalTrap.getOwner().getName());
            par1World.playSoundEffect(par2, par3, par4, "random.anvil_use", 3.0F, 1.0F);
            if (isPlayer)
                MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText("[" + EnumChatFormatting.BLACK + StatCollector.translateToLocal("tile.cageTrap.name") + EnumChatFormatting.RESET + "] " + StatCollector.translateToLocal("messages.cageTrap.captured").replace("#player", ((EntityPlayer) par5Entity).getCommandSenderName()).replace("#location", Utils.getFormattedCoordinates(par2, par3, par4))));
        }
    }
}
Also used : TileEntityCageTrap(net.geforcemods.securitycraft.tileentity.TileEntityCageTrap) EntityMob(net.minecraft.entity.monster.EntityMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOwnable(net.geforcemods.securitycraft.api.IOwnable) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

IOwnable (net.geforcemods.securitycraft.api.IOwnable)2 TileEntityCageTrap (net.geforcemods.securitycraft.tileentity.TileEntityCageTrap)2 EntityMob (net.minecraft.entity.monster.EntityMob)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ChatComponentText (net.minecraft.util.ChatComponentText)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1