Search in sources :

Example 1 with World

use of net.minecraft.world.World in project BetterStorage by copygirl.

the class ClientProxy method drawBlockHighlight.

@SubscribeEvent
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
    EntityPlayer player = event.player;
    World world = player.worldObj;
    MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);
    if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK))
        return;
    int x = target.blockX;
    int y = target.blockY;
    int z = target.blockZ;
    AxisAlignedBB box = null;
    Block block = world.getBlock(x, y, z);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (block instanceof TileArmorStand)
        box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
    else if (block == Blocks.iron_door)
        box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
    else if (tileEntity instanceof IHasAttachments)
        box = getAttachmentPointsHighlightBox(player, tileEntity, target);
    if (box == null)
        return;
    double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
    double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
    double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
    box.offset(-xOff, -yOff, -zOff);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);
    RenderGlobal.drawOutlinedBoundingBox(box, -1);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
    event.setCanceled(true);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TileArmorStand(net.mcft.copy.betterstorage.tile.stand.TileArmorStand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) World(net.minecraft.world.World) IHasAttachments(net.mcft.copy.betterstorage.attachment.IHasAttachments) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with World

use of net.minecraft.world.World in project BetterStorage by copygirl.

the class ItemBackpack method placeBackpack.

/** Place a backpack down on a block.
	 * @param carrier The carrier of the backpack (non-null).
	 * @param player The player placing the backpack, if any.
	 *               Used to check if they're allowed to place it.
	 * @param backpack The backpack stack.
	 *                 Stack size is decreased if placed successfully.
	 * @param side The side of block the backpack is placed on.
	 *             Anything other than top usually doesn't place it.
	 * @param orientation The orientation the backpack will be placed in.
	 * @param despawn If the backpack should despawn after a while.
	 *                True for mobs, unless hit recently.
	 * @param deathDrop True if the backpack is dropped on death.
	 *                  Will not check for block solidity or entities.
	 * @return If the backpack was placed successfully. */
public static boolean placeBackpack(EntityLivingBase carrier, EntityPlayer player, ItemStack backpack, int x, int y, int z, int side, ForgeDirection orientation, boolean despawn, boolean deathDrop) {
    if (backpack.stackSize == 0)
        return false;
    World world = carrier.worldObj;
    Block blockBackpack = ((ItemBackpack) backpack.getItem()).getBlockType();
    // Return false if there's block is too low or too high.
    if ((y <= 0) || (y >= world.getHeight() - 1))
        return false;
    // Otherwise, check if the top side was clicked and adjust the position.
    if (!world.getBlock(x, y, z).isReplaceable(world, x, y, z)) {
        if (side != 1)
            return false;
        y++;
    }
    // If the backpack is dropped on death, return false
    // if it's placed on a non-replaceable block. Otherwise,
    // return false if the block isn't solid on top.
    Block blockBelow = world.getBlock(x, y - 1, z);
    if ((deathDrop ? blockBelow.isReplaceable(world, x, y - 1, z) : !world.isSideSolid(x, y - 1, z, ForgeDirection.UP)))
        return false;
    // Return false if there's an entity blocking the placement.
    if (!world.canPlaceEntityOnSide(blockBackpack, x, y, z, deathDrop, side, carrier, backpack))
        return false;
    // Return false if the player can't edit the block.
    if ((player != null) && (!world.canMineBlock(player, x, y, z) || !player.canPlayerEdit(x, y, z, side, backpack)))
        return false;
    // Do not actually place the backpack on the client.
    if (world.isRemote)
        return true;
    if (!world.setBlock(x, y, z, blockBackpack, orientation.ordinal(), 3))
        return false;
    if (world.getBlock(x, y, z) != blockBackpack)
        return false;
    blockBackpack.onBlockPlacedBy(world, x, y, z, carrier, backpack);
    blockBackpack.onPostBlockPlaced(world, x, y, z, orientation.ordinal());
    TileEntityBackpack te = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
    te.stack = backpack.copy();
    if (ItemBackpack.getBackpack(carrier) == backpack)
        te.unequip(carrier, despawn);
    String sound = blockBackpack.stepSound.func_150496_b();
    float volume = (blockBackpack.stepSound.getVolume() + 1.0F) / 2.0F;
    float pitch = blockBackpack.stepSound.getPitch() * 0.8F;
    world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5F, sound, volume, pitch);
    backpack.stackSize--;
    return true;
}
Also used : TileEntityBackpack(net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

Example 3 with World

use of net.minecraft.world.World in project BetterStorage by copygirl.

the class BackpackHandler method onSpecialSpawn.

@SubscribeEvent
public void onSpecialSpawn(SpecialSpawn event) {
    // When a mob spawns naturally, see if it has a chance to spawn with a backpack.
    EntityLivingBase entity = event.entityLiving;
    World world = entity.worldObj;
    double probability = 0.0;
    for (BetterStorageBackpack.BackpackSpawnEntry entry : BetterStorageBackpack.spawnWithBackpack) {
        if (!entity.getClass().equals(entry.entityClass))
            continue;
        probability = entry.probability;
        break;
    }
    if (!RandomUtils.getBoolean(probability) || entity.isChild())
        return;
    // If entity is a vanilla enderman, replace it with a friendly one.
    if (entity.getClass().equals(EntityEnderman.class)) {
        if ((BetterStorageTiles.enderBackpack != null) && // Don't spawn friendly endermen in the end or end biome, would make them too easy to get.
        (world.provider.dimensionId != 1) && (world.getBiomeGenForCoords((int) entity.posX, (int) entity.posZ) != BiomeGenBase.sky)) {
            EntityFrienderman frienderman = new EntityFrienderman(world);
            frienderman.setPositionAndRotation(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, 0);
            world.spawnEntityInWorld(frienderman);
            ItemBackpack.getBackpackData(frienderman).spawnsWithBackpack = true;
            entity.setDead();
        }
    // Otherwise, just mark it to spawn with a backpack.
    } else if (BetterStorageTiles.backpack != null)
        ItemBackpack.getBackpackData(entity).spawnsWithBackpack = true;
}
Also used : EntityFrienderman(net.mcft.copy.betterstorage.entity.EntityFrienderman) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World) BetterStorageBackpack(net.mcft.copy.betterstorage.api.BetterStorageBackpack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with World

use of net.minecraft.world.World in project BluePower by Qmunity.

the class GateConnectionBase method notifyUpdate.

@Override
public void notifyUpdate() {
    if (gate.getParent() == null || gate.getWorld() == null)
        return;
    ForgeDirection d = getForgeDirection();
    IConnection<? extends IRedstoneDevice> c = gate.getRedstoneConnectionCache().getConnectionOnSide(d);
    if (c == null || c.getB() instanceof DummyRedstoneDevice) {
        World world = gate.getWorld();
        int x = gate.getX(), y = gate.getY(), z = gate.getZ();
        RedstoneHelper.notifyRedstoneUpdate(world, x, y, z, d, true);
    } else {
        RedstoneApi.getInstance().getRedstonePropagator(getGate(), d).propagate();
    }
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DummyRedstoneDevice(com.bluepowermod.redstone.DummyRedstoneDevice) World(net.minecraft.world.World)

Example 5 with World

use of net.minecraft.world.World in project LogisticsPipes by RS485.

the class RemoteOrderer method getPipe.

public static PipeItemsRemoteOrdererLogistics getPipe(ItemStack stack) {
    if (stack == null) {
        return null;
    }
    if (!stack.hasTagCompound()) {
        return null;
    }
    if (!stack.stackTagCompound.hasKey("connectedPipe-x") || !stack.stackTagCompound.hasKey("connectedPipe-y") || !stack.stackTagCompound.hasKey("connectedPipe-z")) {
        return null;
    }
    if (!stack.stackTagCompound.hasKey("connectedPipe-world-dim")) {
        return null;
    }
    int dim = stack.stackTagCompound.getInteger("connectedPipe-world-dim");
    World world = DimensionManager.getWorld(dim);
    if (world == null) {
        return null;
    }
    TileEntity tile = world.getTileEntity(stack.stackTagCompound.getInteger("connectedPipe-x"), stack.stackTagCompound.getInteger("connectedPipe-y"), stack.stackTagCompound.getInteger("connectedPipe-z"));
    if (!(tile instanceof LogisticsTileGenericPipe)) {
        return null;
    }
    CoreUnroutedPipe pipe = ((LogisticsTileGenericPipe) tile).pipe;
    if (pipe instanceof PipeItemsRemoteOrdererLogistics) {
        return (PipeItemsRemoteOrdererLogistics) pipe;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) World(net.minecraft.world.World) PipeItemsRemoteOrdererLogistics(logisticspipes.pipes.PipeItemsRemoteOrdererLogistics)

Aggregations

World (net.minecraft.world.World)260 BlockPos (net.minecraft.util.math.BlockPos)78 ItemStack (net.minecraft.item.ItemStack)58 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)55 EntityPlayer (net.minecraft.entity.player.EntityPlayer)52 TileEntity (net.minecraft.tileentity.TileEntity)45 Block (net.minecraft.block.Block)41 IBlockState (net.minecraft.block.state.IBlockState)37 ArrayList (java.util.ArrayList)19 Entity (net.minecraft.entity.Entity)18 EntityLivingBase (net.minecraft.entity.EntityLivingBase)17 Random (java.util.Random)14 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)14 EntityItem (net.minecraft.entity.item.EntityItem)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)11 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)11 Vec3d (net.minecraft.util.math.Vec3d)10 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9