Search in sources :

Example 1 with Block

use of net.minecraft.block.Block 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 Block

use of net.minecraft.block.Block 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 Block

use of net.minecraft.block.Block in project BetterStorage by copygirl.

the class EntityFrienderman method onLivingUpdate.

@Override
public void onLivingUpdate() {
    if (worldObj.isRemote) {
        super.onLivingUpdate();
        return;
    }
    int x = (int) Math.floor(posX);
    int y = (int) (posY + 0.6);
    int z = (int) Math.floor(posZ);
    GameRules rules = worldObj.getGameRules();
    String ruleBefore = rules.getGameRuleStringValue("mobGriefing");
    boolean ruleChanged = false;
    boolean hasEnderChest = (func_146080_bZ() == Blocks.ender_chest);
    boolean hasBackpack = (getEquipmentInSlot(EquipmentSlot.CHEST) != null);
    // Temporarily change the blocks which endermen can carry.
    // TODO: Make a pull request to Forge which allows us to do this by overriding a method instead.
    IdentityHashMap<Block, Boolean> carriable = ReflectionUtils.get(EntityEnderman.class, null, "carriable", "");
    ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", friendermanCarriable);
    // prevent dropping of enderchests regardless of the gamerule.
    if (hasEnderChest) {
        if (ruleBefore.equalsIgnoreCase("true")) {
            rules.setOrCreateGameRule("mobGriefing", "false");
            ruleChanged = true;
        }
    } else if (hasBackpack && worldObj.isAirBlock(x, y, z)) {
        if (ruleBefore.equalsIgnoreCase("false")) {
            rules.setOrCreateGameRule("mobGriefing", "true");
            ruleChanged = true;
        }
    }
    super.onLivingUpdate();
    // Reset carriable blocks and gamerule.
    ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", carriable);
    if (ruleChanged)
        rules.setOrCreateGameRule("mobGriefing", ruleBefore);
    // If ender chest was picked up, remove ender backpack and place it on the ground.
    if (!hasEnderChest && (func_146080_bZ() == Blocks.ender_chest)) {
        setCurrentItemOrArmor(3, null);
        worldObj.setBlock(x, y, z, BetterStorageTiles.enderBackpack, RandomUtils.getInt(2, 6), 3);
        WorldUtils.get(worldObj, x, y, z, TileEntityBackpack.class).stack = new ItemStack(BetterStorageItems.itemEnderBackpack);
        double px = x + 0.5;
        double py = y + 0.5;
        double pz = z + 0.5;
        BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(px, py, pz, x, y, z), worldObj, px, py, pz, 256);
        worldObj.playSoundEffect(px, py, pz, "mob.endermen.portal", 1.0F, 1.0F);
    }
}
Also used : PacketBackpackTeleport(net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport) GameRules(net.minecraft.world.GameRules) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Block

use of net.minecraft.block.Block in project BetterStorage by copygirl.

the class TileEntityLockable method setPowered.

/** Sets if the chest is emitting redstone.
	 *  Updates all nearby blocks to make sure they notice it. */
public void setPowered(boolean powered) {
    TileEntityLockable chest = ((TileEntityLockable) getMainTileEntity());
    if (chest != this) {
        chest.setPowered(powered);
        return;
    }
    if (this.powered == powered)
        return;
    this.powered = powered;
    Block block = getBlockType();
    // Schedule a block update to turn the redstone signal back off.
    if (powered)
        worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, block, 10);
    // Notify nearby blocks
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, block);
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, block);
    // Notify nearby blocks of adjacent chest
    if (isConnected() && (getConnected() == ForgeDirection.EAST)) {
        worldObj.notifyBlocksOfNeighborChange(xCoord + 2, yCoord, zCoord, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord + 1, zCoord, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord - 1, zCoord, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord + 1, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord - 1, block);
    }
    if (isConnected() && (getConnected() == ForgeDirection.SOUTH)) {
        worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 2, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord + 1, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord + 1, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord + 1, block);
        worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord + 1, block);
    }
}
Also used : Block(net.minecraft.block.Block)

Example 5 with Block

use of net.minecraft.block.Block in project BetterStorage by copygirl.

the class WorldUtils method notifyBlocksAround.

/** This will perform a {@link World#notifyBlockOfNeighborChange()} on every adjacent block including the block at x|y|z.*/
public static void notifyBlocksAround(World world, int x, int y, int z) {
    Block block = world.getBlock(x, y, z);
    world.notifyBlocksOfNeighborChange(x, y, z, block);
    world.notifyBlocksOfNeighborChange(x + 1, y, z, block);
    world.notifyBlocksOfNeighborChange(x - 1, y, z, block);
    world.notifyBlocksOfNeighborChange(x, y + 1, z, block);
    world.notifyBlocksOfNeighborChange(x, y - 1, z, block);
    world.notifyBlocksOfNeighborChange(x, y, z + 1, block);
    world.notifyBlocksOfNeighborChange(x, y, z - 1, block);
}
Also used : Block(net.minecraft.block.Block)

Aggregations

Block (net.minecraft.block.Block)660 IBlockState (net.minecraft.block.state.IBlockState)166 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)104 TileEntity (net.minecraft.tileentity.TileEntity)84 Item (net.minecraft.item.Item)70 ItemBlock (net.minecraft.item.ItemBlock)63 ResourceLocation (net.minecraft.util.ResourceLocation)46 World (net.minecraft.world.World)41 EnumFacing (net.minecraft.util.EnumFacing)38 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)31 EntityPlayer (net.minecraft.entity.player.EntityPlayer)29 ArrayList (java.util.ArrayList)28 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)26 Pos (com.builtbroken.mc.imp.transform.vector.Pos)25 Random (java.util.Random)24 Entity (net.minecraft.entity.Entity)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)21 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)19 List (java.util.List)16