private boolean canPlayerPlaceBlockOrUseItem(World world, EntityPlayer entityplayer) {
   boolean denyPlacement = false;
   String placementMessage = "";
   ItemStack itemstack = entityplayer.getCurrentEquippedItem();
   if (itemstack != null) {
     Object itemHeld = itemstack.getItem();
     ItemBlock itemBlock = null;
     Block block = null;
     Item item = null;
     if (itemHeld instanceof Block) {
       block = (Block) itemHeld;
     }
     if (itemHeld instanceof Item) {
       item = (Item) itemHeld;
     }
     if (itemHeld instanceof ItemBlock) {
       itemBlock = (ItemBlock) itemHeld;
       block = itemBlock.field_150939_a;
     }
     if (block != null) {
       if (!BlockUtil.isBlockAllowed(block)) {
         denyPlacement = true;
         placementMessage = MessageLib.DENY_PLACEMENT;
       }
       if (block.hasTileEntity(0)) {
         if (!BlockUtil.isTileEntityAllowed(block.createTileEntity(world, 0))) {
           denyPlacement = true;
           placementMessage = MessageLib.DENY_PLACEMENT;
         }
       }
     }
     if (item != null) {
       if (item instanceof ItemBlock) {
         Block itemBlockId = ((ItemBlock) item).field_150939_a;
         if (itemBlockId.hasTileEntity(0)) {
           if (!BlockUtil.isTileEntityAllowed(itemBlockId.createTileEntity(world, 0))) {
             denyPlacement = true;
             placementMessage = MessageLib.DENY_PLACEMENT;
           }
         }
       }
       if (!BlockUtil.isItemAllowed(item)) {
         denyPlacement = true;
         placementMessage = MessageLib.DENY_USE;
       }
     }
   }
   if (denyPlacement) {
     ChatHelper.addColouredMessageToPlayer(
         entityplayer, EnumChatFormatting.BOLD, placementMessage);
     return false;
   }
   return true;
 }
예제 #2
0
  /** Only called if the pSTone is active */
  public static Block getRandomBlock() {

    for (Block block : Block.blocksList) {
      if (block != null) {
        boolean hasTile = block.hasTileEntity(0);

        if (block.blockID != 0 && !(hasTile) && block.blockID == Block.dirt.blockID) {
          // this.add(DTrans);
        } else if (block.blockID != 0 && !(hasTile)) {
          Material mat = block.blockMaterial != null ? block.blockMaterial : Material.air;

          if (mat.isSolid()) {

            blocks.add(block);
          }
        }
      }
    }

    Random rand = new Random();

    int random = rand.nextInt(blocks.size());

    Block block = blocks.get(random);

    return block;
  }
예제 #3
0
 public BlockHandler(Block bloc, String... names) {
   super(names[0]);
   this.block = bloc;
   if (block != null) {
     block
         .setBlockName(names[0])
         .setBlockTextureName(names[1])
         .setCreativeTab(Steamcraft.steamTab); // finalizing the block
     if (names.length > 2) {
       oreName = names[2];
     }
     if (block.hasTileEntity(0)) {
       GameRegistry.registerTileEntity(
           block.createTileEntity(null, 0).getClass(), block.getUnlocalizedName());
     }
   }
 }
  @SubscribeEvent
  public void onBlockClick(PlayerInteractEvent e) {
    if (!e.world.isRemote) {
      if (e.action == Action.RIGHT_CLICK_BLOCK
          && CmdDumpBlockData.getWaitForBlockClick(e.entityPlayer.getUniqueID())) {
        StringBuilder sb = new StringBuilder();
        Block blc = e.world.getBlock(e.x, e.y, e.z);
        if (blc == null) {
          return;
        }

        int meta = e.world.getBlockMetadata(e.x, e.y, e.z);

        sb.append(
            "BlockID: "
                + GameData.getBlockRegistry().getNameForObject(blc)
                + "("
                + GameData.getBlockRegistry().getIDForObject(blc)
                + ")\n");
        sb.append(
            "Block name: " + blc.getUnlocalizedName() + " = " + blc.getLocalizedName() + "\n");
        sb.append("XYZ: " + e.x + " " + e.y + " " + e.z + "\n");
        sb.append("Metadata: " + meta + "\n");
        sb.append(
            "Lightlevel: "
                + "block: "
                + e.world.getSavedLightValue(EnumSkyBlock.Block, e.x, e.y, e.z)
                + ", sky: "
                + e.world.getSavedLightValue(EnumSkyBlock.Sky, e.x, e.y, e.z)
                + "\n");
        if (blc.hasTileEntity(meta)) {
          TileEntity te = e.world.getTileEntity(e.x, e.y, e.z);
          if (te != null) {
            NBTTagCompound nbt = new NBTTagCompound();
            te.writeToNBT(nbt);
            sb.append("NBT: {" + CmdDumpItemData.getNBTString(nbt, 1) + "}");
          }
        }

        System.out.println("\n" + sb.toString());

        e.setCanceled(true);
      }
    }
  }
예제 #5
0
  /** Will update this chunk renderer */
  public void updateRenderer(EntityLivingBase p_147892_1_) {
    if (this.needsUpdate) {
      this.needsUpdate = false;
      int var2 = this.posX;
      int var3 = this.posY;
      int var4 = this.posZ;
      int var5 = this.posX + 16;
      int var6 = this.posY + 16;
      int var7 = this.posZ + 16;

      for (int var8 = 0; var8 < 2; ++var8) {
        this.skipRenderPass[var8] = true;
      }

      Chunk.isLit = false;
      HashSet var26 = new HashSet();
      var26.addAll(this.tileEntityRenderers);
      this.tileEntityRenderers.clear();
      Minecraft var9 = Minecraft.getMinecraft();
      EntityLivingBase var10 = var9.renderViewEntity;
      int var11 = MathHelper.floor_double(var10.posX);
      int var12 = MathHelper.floor_double(var10.posY);
      int var13 = MathHelper.floor_double(var10.posZ);
      byte var14 = 1;
      ChunkCache var15 =
          new ChunkCache(
              this.worldObj,
              var2 - var14,
              var3 - var14,
              var4 - var14,
              var5 + var14,
              var6 + var14,
              var7 + var14,
              var14);

      if (!var15.extendedLevelsInChunkCache()) {
        ++chunksUpdated;
        RenderBlocks var16 = new RenderBlocks(var15);
        this.bytesDrawn = 0;
        this.vertexState = null;

        for (int var17 = 0; var17 < 2; ++var17) {
          boolean var18 = false;
          boolean var19 = false;
          boolean var20 = false;

          for (int var21 = var3; var21 < var6; ++var21) {
            for (int var22 = var4; var22 < var7; ++var22) {
              for (int var23 = var2; var23 < var5; ++var23) {
                Block var24 = var15.getBlock(var23, var21, var22);

                if (var24.getMaterial() != Material.air) {
                  if (!var20) {
                    var20 = true;
                    this.preRenderBlocks(var17);
                  }

                  if (var17 == 0 && var24.hasTileEntity()) {
                    TileEntity var25 = var15.getTileEntity(var23, var21, var22);

                    if (TileEntityRendererDispatcher.instance.hasSpecialRenderer(var25)) {
                      this.tileEntityRenderers.add(var25);
                    }
                  }

                  int var28 = var24.getRenderBlockPass();

                  if (var28 > var17) {
                    var18 = true;
                  } else if (var28 == var17) {
                    var19 |= var16.renderBlockByRenderType(var24, var23, var21, var22);

                    if (var24.getRenderType() == 0
                        && var23 == var11
                        && var21 == var12
                        && var22 == var13) {
                      var16.setRenderFromInside(true);
                      var16.setRenderAllFaces(true);
                      var16.renderBlockByRenderType(var24, var23, var21, var22);
                      var16.setRenderFromInside(false);
                      var16.setRenderAllFaces(false);
                    }
                  }
                }
              }
            }
          }

          if (var19) {
            this.skipRenderPass[var17] = false;
          }

          if (var20) {
            this.postRenderBlocks(var17, p_147892_1_);
          } else {
            var19 = false;
          }

          if (!var18) {
            break;
          }
        }
      }

      HashSet var27 = new HashSet();
      var27.addAll(this.tileEntityRenderers);
      var27.removeAll(var26);
      this.tileEntities.addAll(var27);
      var26.removeAll(this.tileEntityRenderers);
      this.tileEntities.removeAll(var26);
      this.isChunkLit = Chunk.isLit;
      this.isInitialized = true;
    }
  }
  @SideOnly(Side.CLIENT)
  @Override
  public MovingObjectPosition collisionRayTrace(
      World world, int x, int y, int z, Vec3 player, Vec3 view) {
    TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);

    if (tile == null) {
      return null;
    }

    List<MovingObjectPosition> returns = new ArrayList<MovingObjectPosition>();

    returns =
        CollisionRayTrace.rayTraceLittleBlocks(this, player, view, x, y, z, returns, tile, isFluid);
    player = player.addVector(-x, -y, -z);
    view = view.addVector(-x, -y, -z);

    returns = CollisionRayTrace.collisionRayTracer(this, world, player, view, x, y, z, returns);
    if (!returns.isEmpty()) {
      MovingObjectPosition min = null;
      double distMin = 0;
      boolean isLiquid = false;
      for (MovingObjectPosition ret : returns) {
        double dist = (double) ret.hitVec.squareDistanceTo(player);

        Block retBlock = tile.getBlock(ret.blockX, ret.blockY, ret.blockZ);
        if (retBlock != Blocks.air) {
          isLiquid = retBlock instanceof IFluidBlock;
          if (isLiquid && isFluid) {
            isLiquid =
                !(retBlock instanceof BlockStaticLiquid
                    && tile.getBlockMetadata(ret.blockX, ret.blockY, ret.blockZ) == 0);
          }
        }

        if ((min == null || dist < distMin) && !isLiquid) {
          distMin = dist;
          min = ret;
        }
      }
      Block littleBlock = tile.getBlock(xSelected, ySelected, zSelected);

      if (min != null) {
        side = (byte) min.sideHit;
        xSelected = (int) min.blockX;
        ySelected = (int) min.blockY;
        zSelected = (int) min.blockZ;
        if (isFluid) {
          littleBlock = tile.getBlock(xSelected, ySelected, zSelected);
        }
        boolean rayTraced = false;
        if (littleBlock != Blocks.air) {
          if (littleBlock != null) {
            if (!(littleBlock.hasTileEntity(tile.getBlockMetadata(xSelected, ySelected, zSelected))
                && tile.getChunkTileEntity(xSelected, ySelected, zSelected) == null)) {

              try {
                littleBlock.collisionRayTrace(
                    (World) tile.getLittleWorld(),
                    (x << 3) + xSelected,
                    (y << 3) + ySelected,
                    (z << 3) + zSelected,
                    player,
                    view);
              } catch (ClassCastException e) {
                FMLCommonHandler.instance().getFMLLogger().warn(e.getLocalizedMessage());
              }
            }
          }
        }
        this.setBlockBoundsBasedOnSelection(world, x, y, z);
        return new MovingObjectPosition(
            x,
            y,
            z,
            (byte) min.sideHit,
            /** ((Vec3) min.hitVec).addVector(x, y, z) * */
            hitVec =
                Vec3.createVectorHelper(
                        (min.hitVec.xCoord * 8) % 1,
                        (min.hitVec.yCoord * 8) % 1,
                        (min.hitVec.zCoord * 8) % 1)
                    .addVector(x, y, z));
      }
    }
    xSelected = -10;
    ySelected = -10;
    zSelected = -10;
    side = -1;
    hitVec = null;
    this.setBlockBoundsBasedOnSelection(world, x, y, z);

    return null;
  }