Exemplo n.º 1
0
 private void runThroughNetwork(BlockPos pos) {
   for (EnumFacing facing : EnumFacing.values()) {
     BlockPos searchPos = pos.offset(facing);
     if (worldObj.getTileEntity(pos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(pos)).getNeighborFaces().contains(facing))
       continue;
     if (worldObj.getTileEntity(searchPos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(searchPos))
             .getNeighborFaces()
             .contains(facing.getOpposite())) continue;
     if (!getWorld().isAirBlock(searchPos)) {
       TileEntity tile = getWorld().getTileEntity(searchPos);
       if (tile != null) {
         if (tile instanceof TileNetworkCore && !tile.getPos().equals(this.pos)) {
           worldObj.setBlockToAir(searchPos);
           worldObj.playEvent(2001, searchPos, Block.getIdFromBlock(Registry.networkCore));
           StackHelper.spawnItemStack(worldObj, searchPos, new ItemStack(Registry.networkCore));
           markForNetworkInit();
         } else if (tile instanceof INetworkPart && !network.networkParts.contains(tile)) {
           network.addPart((INetworkPart) tile);
         } else if (InvHelper.hasItemHandler(tile, facing.getOpposite())
             && !network.networkParts.contains(
                 InvHelper.getItemHandler(tile, facing.getOpposite()))) {
           network.addPart(
               new InventoryNetworkPart(
                   tile.getWorld(),
                   searchPos,
                   InvHelper.getItemHandler(tile, facing.getOpposite())));
         } else continue;
         runThroughNetwork(searchPos);
       }
     }
   }
 }
Exemplo n.º 2
0
  /**
   * Gets a list of all capabilities that touch a BlockPos. This will search for tile entities
   * touching the BlockPos and then query them for access to their capabilities.
   *
   * @param capability The capability you want to retrieve.
   * @param world The world that this is happening in.
   * @param pos The position to search around.
   * @return A list of all capabilities that are being held by connected blocks.
   */
  public static <T> List<T> getConnectedCapabilities(
      Capability<T> capability, World world, BlockPos pos) {

    final List<T> capabilities = new ArrayList<T>();

    for (final EnumFacing side : EnumFacing.values()) {

      final TileEntity tile = world.getTileEntity(pos.offset(side));

      if (tile != null && !tile.isInvalid() && tile.hasCapability(capability, side.getOpposite()))
        capabilities.add(tile.getCapability(capability, side.getOpposite()));
    }

    return capabilities;
  }
    public void iterate(Coord4D from, EnumFacing fromDirection) {
      if (iterated.contains(from)) {
        return;
      }

      iterated.add(from);

      if (orphanTransmitters.containsKey(from)) {
        IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);

        if (transmitter.isValid() && transmitter.isOrphan()) {
          connectedTransmitters.add(transmitter);
          transmitter.setOrphan(false);

          for (EnumFacing direction : EnumFacing.VALUES) {
            if (direction != fromDirection) {
              Coord4D directionCoord =
                  transmitter.getAdjacentConnectableTransmitterCoord(direction);

              if (!(directionCoord == null || iterated.contains(directionCoord))) {
                iterate(directionCoord, direction.getOpposite());
              }
            }
          }
        }
      } else {
        addNetworkToIterated(from);
      }
    }
Exemplo n.º 4
0
  @SideOnly(Side.CLIENT)
  public void randomDisplayTick(World pos, BlockPos state, IBlockState worldIn, Random rand) {
    EnumFacing enumfacing = (EnumFacing) worldIn.getValue(FACING);
    double d0 = (double) state.getX() + 0.5D;
    double d1 = (double) state.getY() + 0.7D;
    double d2 = (double) state.getZ() + 0.5D;
    double d3 = 0.22D;
    double d4 = 0.27D;

    if (enumfacing.getAxis().isHorizontal()) {
      EnumFacing enumfacing1 = enumfacing.getOpposite();
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          0.0D,
          5.0D,
          0.0D,
          new int[0]);
      pos.spawnParticle(
          EnumParticleTypes.REDSTONE,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          -9.0D,
          9.0D,
          -9.0D,
          new int[0]);
    } else {
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT, d0, d1, d2, 0.0D, 5.0D, 0.0D, new int[0]);
      pos.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, -9.0D, 9.0D, -9.0D, new int[0]);
    }
  }
Exemplo n.º 5
0
  private static EnumFacing getFlippedFacing(final EnumFacing axis, final EnumFacing side) {
    if (axis.getAxis() == side.getAxis()) {
      return side.getOpposite();
    }

    return side;
  }
Exemplo n.º 6
0
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      @Nullable ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      state = state.withProperty(OPEN, Boolean.valueOf(false));
      worldIn.setBlockState(pos, state, 10);
    } else {
      EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);

      if (state.getValue(FACING) == enumfacing.getOpposite()) {
        state = state.withProperty(FACING, enumfacing);
      }

      state = state.withProperty(OPEN, Boolean.valueOf(true));
      worldIn.setBlockState(pos, state, 10);
    }

    worldIn.playEvent(
        playerIn, ((Boolean) state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
    return true;
  }
  public void eventHandler(PipeEventItem.FindDest event) {
    LinkedList<EnumFacing> newOris = new LinkedList<EnumFacing>();

    for (int o = 0; o < 6; ++o) {
      EnumFacing orientation = EnumFacing.VALUES[o];

      // commented out during port from BC 4.2 to 6.1
      // I don't know what the equivalent to the Position argument to filterPossibleMovements() is
      // in the new eventHandler system
      // if(orientation != pos.orientation.getOpposite())
      {
        TileEntity entity = container.getTile(orientation);
        if (entity instanceof IInventory) {
          IInventory inventory = (IInventory) entity;

          if (InventoryUtils.containsItem(true, false, event.item.getItemStack(), inventory)) {
            ITransactor transactor = Transactor.getTransactorFor(entity, orientation.getOpposite());
            if (transactor.add(event.item.getItemStack(), false).stackSize > 0) {
              newOris.add(orientation);
            }
          } else {
            event.destinations.remove(orientation);
          }
        }
      }
    }

    if (!newOris.isEmpty()) {
      event.destinations.clear();
      event.destinations.addAll(newOris);
    } else {

    }
  }
Exemplo n.º 8
0
 protected static boolean func_181088_a(
     World p_181088_0_, BlockPos p_181088_1_, EnumFacing p_181088_2_) {
   return p_181088_2_ == EnumFacing.DOWN
           && World.doesBlockHaveSolidTopSurface(p_181088_0_, p_181088_1_.down())
       ? true
       : p_181088_0_.isSideSolid(p_181088_1_.offset(p_181088_2_), p_181088_2_.getOpposite());
 }
Exemplo n.º 9
0
  @Override
  public void onNeighborBlockChange(Block block) {
    if (!getWorld()
        .getBlockState(getPos().offset(side))
        .getBlock()
        .isSideSolid(getWorld(), getPos().offset(side), side.getOpposite())) {
      harvest(null, null);
      return;
    }

    onChanged();
  }
Exemplo n.º 10
0
 @Override
 public IBlockState onBlockPlaced(
     World worldIn,
     BlockPos pos,
     EnumFacing facing,
     float hitX,
     float hitY,
     float hitZ,
     int meta,
     EntityLivingBase placer) {
   EnumFacing f = TomsModUtils.getDirectionFacing(placer, false);
   return this.getDefaultState().withProperty(FACING, f.getOpposite()).withProperty(ACTIVE, false);
 }
Exemplo n.º 11
0
  private boolean updateInputs() {
    byte[] oldOutput = new byte[4];
    boolean changed = false;

    for (int i = 0; i <= 3; i++) {
      Connection conn = getType(side);
      if (conn.isOutput() && conn.isRedstone()) {
        oldOutput[i] = getOutputOutside(side);
      }
    }
    for (int i = 0; i <= 3; i++) {
      EnumFacing side = EnumFacing.getFront(i + 2);
      Connection conn = getType(side);
      if (conn.isInput() && conn.isRedstone()) {
        EnumFacing real = gateToReal(side);
        byte oi = inputs[i];
        World w = getWorld();
        BlockPos p = getPos().offset(real);
        IMultipartContainer container = MultipartHelper.getPartContainer(w, p);
        if (container != null) {
          inputs[i] =
              (byte)
                  MultipartRedstoneHelper.getWeakSignal(container, real.getOpposite(), this.side);
        } else {
          IBlockState s = w.getBlockState(p);
          inputs[i] = (byte) s.getBlock().getWeakPower(w, p, s, real);
        }

        if (conn.isDigital()) {
          inputs[i] = inputs[i] != 0 ? (byte) 15 : 0;
        }
        if (inputs[i] != oi) {
          changed = true;
        }
      }
    }

    if (!changed) {
      for (int i = 0; i <= 3; i++) {
        Connection conn = getType(side);
        if (conn.isOutput() && conn.isRedstone()) {
          if (getOutputOutside(side) != oldOutput[i]) {
            changed = true;
            break;
          }
        }
      }
    }

    return changed;
  }
Exemplo n.º 12
0
  protected TileEntityChest getAdjacentChest(EnumFacing side) {
    BlockPos blockpos = this.pos.offset(side);

    if (this.isChestAt(blockpos)) {
      TileEntity tileentity = this.worldObj.getTileEntity(blockpos);

      if (tileentity instanceof TileEntityChest) {
        TileEntityChest tileentitychest = (TileEntityChest) tileentity;
        tileentitychest.func_174910_a(this, side.getOpposite());
        return tileentitychest;
      }
    }

    return null;
  }
Exemplo n.º 13
0
  @Override
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    // we allow to insert buckets into the smeltery
    TileEntity te = worldIn.getTileEntity(pos);
    if (!(te instanceof IFluidHandler)) {
      return false;
    }
    IFluidHandler tank = (IFluidHandler) te;
    side = side.getOpposite();

    ItemStack stack = player.getHeldItem();
    if (stack == null) {
      return false;
    }

    // regular bucket
    ItemStack result = FluidUtil.tryEmptyBucket(stack, tank, side);
    if (result != null) {
      if (!player.capabilities.isCreativeMode) {
        player.inventory.decrStackSize(player.inventory.currentItem, 1);
        PlayerHelper.spawnItemAtPlayer(player, result);
      }
      return true;
    }

    // universal bucket
    ItemStack copy = stack.copy();
    if (FluidUtil.tryEmptyFluidContainerItem(stack, tank, side, player)) {
      if (player.capabilities.isCreativeMode) {
        // reset the stack that got modified
        player.inventory.setInventorySlotContents(player.inventory.currentItem, copy);
      }
      return true;
    }

    // prevent interaction of the item if it's a fluidcontainer. Prevents placing liquids when
    // interacting with the tank
    return FluidContainerRegistry.isFilledContainer(stack)
        || stack.getItem() instanceof IFluidContainerItem;
  }
  private int getNeighborEncouragement(World worldIn, BlockPos pos) {
    if (!worldIn.isAirBlock(pos)) return 0;
    else {
      int i = 0;

      for (EnumFacing enumfacing : EnumFacing.values())
        i =
            Math.max(
                worldIn
                    .getBlockState(pos.offset(enumfacing))
                    .getBlock()
                    .getFlammability(worldIn, pos.offset(enumfacing), enumfacing.getOpposite()),
                i);

      return i;
    }
  }
Exemplo n.º 15
0
  public EnumFacing gateToReal(EnumFacing dir) {
    if (dir.getAxis() == EnumFacing.Axis.Y) {
      return null;
    }

    if (dir.getAxis() == EnumFacing.Axis.X && mirrored) {
      dir = dir.getOpposite();
    }

    EnumFacing itop = top;
    while (itop != EnumFacing.NORTH) {
      dir = dir.rotateY();
      itop = itop.rotateYCCW();
    }

    return CONNECTION_DIRS[side.ordinal()][dir.ordinal() - 2];
  }
Exemplo n.º 16
0
 /**
  * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments
  * to the IBlockstate
  */
 public IBlockState onBlockPlaced(
     World worldIn,
     BlockPos pos,
     EnumFacing facing,
     float hitX,
     float hitY,
     float hitZ,
     int meta,
     EntityLivingBase placer) {
   return func_181088_a(worldIn, pos, facing.getOpposite())
       ? this.getDefaultState()
           .withProperty(FACING, facing)
           .withProperty(POWERED, Boolean.valueOf(false))
       : this.getDefaultState()
           .withProperty(FACING, EnumFacing.DOWN)
           .withProperty(POWERED, Boolean.valueOf(false));
 }
Exemplo n.º 17
0
  public EnumFacing realToGate(EnumFacing rdir) {
    if (rdir.getAxis() == side.getAxis()) {
      return null;
    }

    for (int i = 0; i < 4; i++) {
      if (CONNECTION_DIRS[side.ordinal()][i] == rdir) {
        EnumFacing dir = EnumFacing.getFront(i + 2);
        EnumFacing itop = top;
        while (itop != EnumFacing.NORTH) {
          dir = dir.rotateYCCW();
          itop = itop.rotateYCCW();
        }
        if (dir.getAxis() == EnumFacing.Axis.X && mirrored) {
          return dir.getOpposite();
        } else {
          return dir;
        }
      }
    }

    return null;
  }
Exemplo n.º 18
0
  @Override
  public void propagate(int color) {
    if (DEBUG) {
      System.out.println(
          "--- PROPAGATE "
              + getPos().toString()
              + " "
              + location.name()
              + " ("
              + getWorld().getTotalWorldTime()
              + ") ---");
    }

    int maxSignal = 0;
    int oldSignal = signalLevel;
    int[] neighborLevel = new int[7];
    boolean[] isWire = new boolean[7];
    boolean hasRedstoneWire = false;

    if (type == WireKind.NORMAL) {
      if (location != WireFace.CENTER) {
        EnumFacing facing = location.facing;

        BlockPos pos = getPos().offset(facing);
        IBlockState state = getWorld().getBlockState(pos);

        int power = WireUtils.getRedstoneLevel(getWorld(), pos, state, facing, location, false);

        if (power > 0) {
          neighborLevel[facing.ordinal()] = Math.min(15, power) << 8 | 0xFF;
        }
      }
    }

    if (internalConnections > 0) {
      for (WireFace location : WireFace.VALUES) {
        if (connectsInternal(location)) {
          isWire[location.ordinal()] = true;
          neighborLevel[location.ordinal()] = getRedstoneLevel(getContainer(), location);
        }
      }
    }

    for (EnumFacing facing : EnumFacing.VALUES) {
      int facidx = facing.ordinal();

      if (facing == location.facing && type == WireKind.NORMAL) {
        BlockPos pos = getPos().offset(facing);
        int i = 0;

        for (EnumFacing enumfacing : EnumFacing.values()) {
          if (enumfacing == facing.getOpposite()) {
            continue;
          }

          IBlockState state = getWorld().getBlockState(pos.offset(enumfacing));
          Block block = state.getBlock();

          if (!(block instanceof BlockRedstoneWire)) {
            int power =
                WireUtils.getRedstoneLevel(
                    getWorld(), pos.offset(enumfacing), state, enumfacing, location, true);

            if (power >= 15) {
              i = 15;
              break;
            }

            if (power > i) {
              i = power;
            }
          }
        }

        if (i > 0) {
          neighborLevel[facidx] = (i << 8) | 0xFF;
        }
      } else if (connectsExternal(facing)) {
        BlockPos pos = getPos().offset(facing);
        IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), pos);

        if (WireUtils.getWire(container, location) != null) {
          isWire[facidx] = true;
          neighborLevel[facidx] = getRedstoneLevel(container, location);
        } else {
          IBlockState state = getWorld().getBlockState(pos);

          int power = WireUtils.getRedstoneLevel(getWorld(), pos, state, facing, location, true);

          if (state.getBlock() instanceof BlockRedstoneWire) {
            isWire[facidx] = true;
            hasRedstoneWire = true;
            power--;
          }

          if (power > 0) {
            neighborLevel[facidx] = (Math.min(power, 15) << 8) | 0xFF;
          }
        }
      } else if (connectsCorner(facing)) {
        IMultipartContainer container =
            MultipartHelper.getPartContainer(
                getWorld(), getPos().offset(facing).offset(location.facing));
        if (container != null) {
          isWire[facidx] = true;
          neighborLevel[facidx] = getRedstoneLevel(container, WireFace.get(facing.getOpposite()));
        }
      }
    }

    int maxSignalNonWire = 0;

    for (int i = 0; i < 7; i++) {
      if (neighborLevel[i] > maxSignal) {
        maxSignal = neighborLevel[i];
      }
      if (!isWire[i] && neighborLevel[i] > maxSignalNonWire) {
        maxSignalNonWire = neighborLevel[i];
      }
    }

    if (DEBUG) {
      System.out.println(
          "ConnectionCache: "
              + Integer.toBinaryString(internalConnections)
              + " "
              + Integer.toBinaryString(externalConnections)
              + " "
              + Integer.toBinaryString(cornerConnections));
      System.out.println("Levels: " + Arrays.toString(neighborLevel));
    }

    if (maxSignal > signalLevel) {
      signalLevel = maxSignal - 1;
      if ((signalLevel & 0xFF) == 0 || (signalLevel & 0xFF) == 0xFF) {
        signalLevel = 0;
      }
    } else {
      signalLevel = maxSignalNonWire;
    }

    if (oldSignal == signalLevel) {
      return;
    }

    if (DEBUG) {
      System.out.println("Switch: " + oldSignal + " -> " + signalLevel);
    }

    if (signalLevel == 0) {
      for (WireFace nLoc : WireFace.VALUES) {
        if (connectsInternal(nLoc)) {
          if (neighborLevel[nLoc.ordinal()] > 0) {
            WireUtils.getWire(getContainer(), nLoc).onSignalChanged(type.color());
          }
        } else if (nLoc != WireFace.CENTER) {
          EnumFacing facing = nLoc.facing;

          if (connectsExternal(facing)) {
            IMultipartContainer container =
                MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
            if (container == null
                || WireUtils.getWire(container, location) == null
                || neighborLevel[facing.ordinal()] > 0) {
              propagateNotify(facing, type.color());
            }
          } else if (connectsCorner(facing)) {
            if (neighborLevel[nLoc.ordinal()] > 0) {
              propagateNotifyCorner(location.facing, facing, type.color());
            }
          } else if (type == WireKind.NORMAL && facing.getOpposite() != location.facing) {
            TileEntity nt = getWorld().getTileEntity(getPos().offset(facing));
            if (!(nt instanceof IRedstoneReceiver)) {
              getWorld()
                  .notifyBlockOfStateChange(getPos().offset(facing), MCMultiPartMod.multipart);
            }
          }
        }
      }
    } else {
      for (WireFace nLoc : WireFace.VALUES) {
        if (neighborLevel[nLoc.ordinal()] < signalLevel - 1
            || neighborLevel[nLoc.ordinal()] > (signalLevel + 1)) {
          if (connectsInternal(nLoc)) {
            WireUtils.getWire(getContainer(), nLoc).onSignalChanged(type.color());
          } else if (nLoc != WireFace.CENTER) {
            EnumFacing facing = nLoc.facing;

            if (connectsExternal(facing)) {
              propagateNotify(facing, type.color());
            } else if (connectsCorner(facing)) {
              propagateNotifyCorner(location.facing, facing, type.color());
            } else if (type == WireKind.NORMAL && facing.getOpposite() != location.facing) {
              TileEntity nt = getWorld().getTileEntity(getPos().offset(facing));
              if (!(nt instanceof IRedstoneReceiver)) {
                getWorld()
                    .notifyBlockOfStateChange(getPos().offset(facing), MCMultiPartMod.multipart);
              }
            }
          }
        }
      }
    }

    if (type == WireKind.NORMAL) {
      if ((oldSignal & 0xF00) != (signalLevel & 0xF00)) {
        scheduleRenderUpdate();

        if (location != WireFace.CENTER) {
          BlockPos uPos = getPos().offset(location.facing);
          getWorld()
              .notifyNeighborsOfStateExcept(
                  uPos, MCMultiPartMod.multipart, location.facing.getOpposite());
        }
      }
    } else {
      if ((oldSignal & 0xF00) != (signalLevel & 0xF00)) {
        if (location != WireFace.CENTER) {
          getWorld()
              .notifyBlockOfStateChange(getPos().offset(location.facing), MCMultiPartMod.multipart);
        }
      }
    }

    finishPropagation();
  }
  private boolean canNeighborCatchFire(World worldIn, BlockPos pos) {
    for (EnumFacing enumfacing : EnumFacing.values())
      if (this.canCatchFire(worldIn, pos.offset(enumfacing), enumfacing.getOpposite())) return true;

    return false;
  }
Exemplo n.º 20
0
 @Override
 public EnumFacing[] getValidRotations() {
   return new EnumFacing[] {side, side.getOpposite()};
 }
Exemplo n.º 21
0
  @Override
  public void setupTerrain(
      final Entity viewEntity,
      final double partialTicks,
      final ICamera camera,
      final int frameCount,
      final boolean playerSpectator) {
    if (ConfigurationHandler.renderDistance != this.renderDistanceChunks
        || this.vboEnabled != OpenGlHelper.useVbo()) {
      loadRenderers();
    }

    this.profiler.startSection("camera");
    final double posX = PLAYER_POSITION_OFFSET.x;
    final double posY = PLAYER_POSITION_OFFSET.y;
    final double posZ = PLAYER_POSITION_OFFSET.z;

    final double deltaX = posX - this.frustumUpdatePosX;
    final double deltaY = posY - this.frustumUpdatePosY;
    final double deltaZ = posZ - this.frustumUpdatePosZ;

    final int chunkCoordX = MathHelper.floor_double(posX) >> 4;
    final int chunkCoordY = MathHelper.floor_double(posY) >> 4;
    final int chunkCoordZ = MathHelper.floor_double(posZ) >> 4;

    if (this.frustumUpdatePosChunkX != chunkCoordX
        || this.frustumUpdatePosChunkY != chunkCoordY
        || this.frustumUpdatePosChunkZ != chunkCoordZ
        || deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ > 16.0) {
      this.frustumUpdatePosX = posX;
      this.frustumUpdatePosY = posY;
      this.frustumUpdatePosZ = posZ;
      this.frustumUpdatePosChunkX = chunkCoordX;
      this.frustumUpdatePosChunkY = chunkCoordY;
      this.frustumUpdatePosChunkZ = chunkCoordZ;
      this.viewFrustum.updateChunkPositions(posX, posZ);
    }

    this.profiler.endStartSection("renderlistcamera");
    this.renderContainer.initialize(posX, posY, posZ);

    this.profiler.endStartSection("culling");
    final BlockPos posEye = new BlockPos(posX, posY + viewEntity.getEyeHeight(), posZ);
    final RenderChunk renderchunk = this.viewFrustum.getRenderChunk(posEye);
    final RenderOverlay renderoverlay = this.viewFrustum.getRenderOverlay(posEye);

    this.displayListEntitiesDirty =
        this.displayListEntitiesDirty
            || !this.chunksToUpdate.isEmpty()
            || posX != this.lastViewEntityX
            || posY != this.lastViewEntityY
            || posZ != this.lastViewEntityZ
            || viewEntity.rotationPitch != this.lastViewEntityPitch
            || viewEntity.rotationYaw != this.lastViewEntityYaw;
    this.lastViewEntityX = posX;
    this.lastViewEntityY = posY;
    this.lastViewEntityZ = posZ;
    this.lastViewEntityPitch = viewEntity.rotationPitch;
    this.lastViewEntityYaw = viewEntity.rotationYaw;

    if (this.displayListEntitiesDirty) {
      this.displayListEntitiesDirty = false;
      this.renderInfos = Lists.newArrayListWithCapacity(CHUNKS);

      final LinkedList<ContainerLocalRenderInformation> renderInfoList = Lists.newLinkedList();
      boolean renderChunksMany = this.mc.renderChunksMany;

      if (renderchunk == null) {
        final int chunkY = posEye.getY() > 0 ? 248 : 8;

        for (int chunkX = -this.renderDistanceChunks;
            chunkX <= this.renderDistanceChunks;
            chunkX++) {
          for (int chunkZ = -this.renderDistanceChunks;
              chunkZ <= this.renderDistanceChunks;
              chunkZ++) {
            final BlockPos pos = new BlockPos((chunkX << 4) + 8, chunkY, (chunkZ << 4) + 8);
            final RenderChunk renderChunk = this.viewFrustum.getRenderChunk(pos);
            final RenderOverlay renderOverlay = this.viewFrustum.getRenderOverlay(pos);

            if (renderChunk != null && camera.isBoundingBoxInFrustum(renderChunk.boundingBox)) {
              renderChunk.setFrameIndex(frameCount);
              renderOverlay.setFrameIndex(frameCount);
              renderInfoList.add(
                  new ContainerLocalRenderInformation(renderChunk, renderOverlay, null, 0));
            }
          }
        }
      } else {
        boolean add = false;
        final ContainerLocalRenderInformation renderInfo =
            new ContainerLocalRenderInformation(renderchunk, renderoverlay, null, 0);
        final Set<EnumFacing> visibleSides = getVisibleSides(posEye);

        if (!visibleSides.isEmpty() && visibleSides.size() == 1) {
          final Vector3f viewVector = getViewVector(viewEntity, partialTicks);
          final EnumFacing facing =
              EnumFacing.getFacingFromVector(viewVector.x, viewVector.y, viewVector.z)
                  .getOpposite();
          visibleSides.remove(facing);
        }

        if (visibleSides.isEmpty()) {
          add = true;
        }

        if (add && !playerSpectator) {
          this.renderInfos.add(renderInfo);
        } else {
          if (playerSpectator && this.world.getBlockState(posEye).getBlock().isOpaqueCube()) {
            renderChunksMany = false;
          }

          renderchunk.setFrameIndex(frameCount);
          renderoverlay.setFrameIndex(frameCount);
          renderInfoList.add(renderInfo);
        }
      }

      while (!renderInfoList.isEmpty()) {
        final ContainerLocalRenderInformation renderInfo = renderInfoList.poll();
        final RenderChunk renderChunk = renderInfo.renderChunk;
        final EnumFacing facing = renderInfo.facing;
        final BlockPos posChunk = renderChunk.getPosition();
        this.renderInfos.add(renderInfo);

        for (final EnumFacing side : EnumFacing.VALUES) {
          final RenderChunk neighborRenderChunk = getNeighborRenderChunk(posEye, posChunk, side);
          final RenderOverlay neighborRenderOverlay =
              getNeighborRenderOverlay(posEye, posChunk, side);

          if ((!renderChunksMany || !renderInfo.setFacing.contains(side.getOpposite()))
              && (!renderChunksMany
                  || facing == null
                  || renderChunk.getCompiledChunk().isVisible(facing.getOpposite(), side))
              && neighborRenderChunk != null
              && neighborRenderChunk.setFrameIndex(frameCount)
              && camera.isBoundingBoxInFrustum(neighborRenderChunk.boundingBox)) {
            final ContainerLocalRenderInformation renderInfoNext =
                new ContainerLocalRenderInformation(
                    neighborRenderChunk, neighborRenderOverlay, side, renderInfo.counter + 1);
            renderInfoNext.setFacing.addAll(renderInfo.setFacing);
            renderInfoNext.setFacing.add(side);
            renderInfoList.add(renderInfoNext);
          }
        }
      }
    }

    this.renderDispatcher.clearChunkUpdates();
    this.renderDispatcherOverlay.clearChunkUpdates();
    final Set<RenderChunk> set = this.chunksToUpdate;
    final Set<RenderOverlay> set1 = this.overlaysToUpdate;
    this.chunksToUpdate = Sets.newLinkedHashSet();

    for (final ContainerLocalRenderInformation renderInfo : this.renderInfos) {
      final RenderChunk renderChunk = renderInfo.renderChunk;
      final RenderOverlay renderOverlay = renderInfo.renderOverlay;

      if (renderChunk.isNeedsUpdate()
          || renderChunk.isCompileTaskPending()
          || set.contains(renderChunk)) {
        this.displayListEntitiesDirty = true;

        this.chunksToUpdate.add(renderChunk);
      }

      if (renderOverlay.isNeedsUpdate()
          || renderOverlay.isCompileTaskPending()
          || set1.contains(renderOverlay)) {
        this.displayListEntitiesDirty = true;

        this.overlaysToUpdate.add(renderOverlay);
      }
    }

    this.chunksToUpdate.addAll(set);
    this.overlaysToUpdate.addAll(set1);
    this.profiler.endSection();
  }
Exemplo n.º 22
0
    public BakedFluid(
        Optional<TRSRTransformation> transformation,
        ImmutableMap<TransformType, TRSRTransformation> transforms,
        VertexFormat format,
        int color,
        TextureAtlasSprite still,
        TextureAtlasSprite flowing,
        boolean gas,
        boolean statePresent,
        int[] cornerRound,
        int flowRound) {
      this.transformation = transformation;
      this.transforms = transforms;
      this.format = format;
      this.color = color;
      this.still = still;
      this.flowing = flowing;
      this.gas = gas;

      faceQuads = Maps.newEnumMap(EnumFacing.class);
      for (EnumFacing side : EnumFacing.values()) {
        faceQuads.put(side, ImmutableList.<BakedQuad>of());
      }

      if (statePresent) {
        float[] y = new float[4];
        for (int i = 0; i < 4; i++) {
          if (gas) {
            y[i] = 1 - cornerRound[i] / 768f;
          } else {
            y[i] = cornerRound[i] / 768f;
          }
        }

        float flow = (float) Math.toRadians(flowRound);

        // top

        TextureAtlasSprite topSprite = flowing;
        float scale = 4;
        if (flow < -17F) {
          flow = 0;
          scale = 8;
          topSprite = still;
        }

        float c = MathHelper.cos(flow) * scale;
        float s = MathHelper.sin(flow) * scale;

        EnumFacing side = gas ? EnumFacing.DOWN : EnumFacing.UP;
        UnpackedBakedQuad.Builder builder;
        ImmutableList.Builder<BakedQuad> topFaceBuilder = ImmutableList.builder();
        for (int k = 0; k < 2; k++) {
          builder = new UnpackedBakedQuad.Builder(format);
          builder.setQuadOrientation(side);
          builder.setTexture(topSprite);
          for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) {
            int l = (k * 3) + (1 - 2 * k) * i;
            putVertex(
                builder,
                side,
                x[l],
                y[l],
                z[l],
                topSprite.getInterpolatedU(8 + c * (x[l] * 2 - 1) + s * (z[l] * 2 - 1)),
                topSprite.getInterpolatedV(
                    8 + c * (x[(l + 1) % 4] * 2 - 1) + s * (z[(l + 1) % 4] * 2 - 1)));
          }
          topFaceBuilder.add(builder.build());
        }
        faceQuads.put(side, topFaceBuilder.build());

        // bottom

        side = side.getOpposite();
        builder = new UnpackedBakedQuad.Builder(format);
        builder.setQuadOrientation(side);
        builder.setTexture(still);
        for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) {
          putVertex(
              builder,
              side,
              z[i],
              gas ? 1 : 0,
              x[i],
              still.getInterpolatedU(z[i] * 16),
              still.getInterpolatedV(x[i] * 16));
        }
        faceQuads.put(side, ImmutableList.<BakedQuad>of(builder.build()));

        // sides

        for (int i = 0; i < 4; i++) {
          side = EnumFacing.getHorizontal((5 - i) % 4);
          BakedQuad q[] = new BakedQuad[2];

          for (int k = 0; k < 2; k++) {
            builder = new UnpackedBakedQuad.Builder(format);
            builder.setQuadOrientation(side);
            builder.setTexture(flowing);
            for (int j = 0; j < 4; j++) {
              int l = (k * 3) + (1 - 2 * k) * j;
              float yl = z[l] * y[(i + x[l]) % 4];
              if (gas && z[l] == 0) yl = 1;
              putVertex(
                  builder,
                  side,
                  x[(i + x[l]) % 4],
                  yl,
                  z[(i + x[l]) % 4],
                  flowing.getInterpolatedU(x[l] * 8),
                  flowing.getInterpolatedV((gas ? yl : 1 - yl) * 8));
            }
            q[k] = builder.build();
          }
          faceQuads.put(side, ImmutableList.of(q[0], q[1]));
        }
      } else {
        // 1 quad for inventory
        UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
        builder.setQuadOrientation(EnumFacing.UP);
        builder.setTexture(still);
        for (int i = 0; i < 4; i++) {
          putVertex(
              builder,
              EnumFacing.UP,
              z[i],
              x[i],
              0,
              still.getInterpolatedU(z[i] * 16),
              still.getInterpolatedV(x[i] * 16));
        }
        faceQuads.put(EnumFacing.SOUTH, ImmutableList.<BakedQuad>of(builder.build()));
      }
    }
Exemplo n.º 23
0
  private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending) {
    if (!extending) {
      worldIn.setBlockToAir(pos.offset(direction));
    }

    BlockPistonStructureHelper blockpistonstructurehelper =
        new BlockPistonStructureHelper(worldIn, pos, direction, extending);
    List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
    List<BlockPos> list1 = blockpistonstructurehelper.getBlocksToDestroy();

    if (!blockpistonstructurehelper.canMove()) {
      return false;
    } else {
      int i = list.size() + list1.size();
      Block[] ablock = new Block[i];
      EnumFacing enumfacing = extending ? direction : direction.getOpposite();

      for (int j = list1.size() - 1; j >= 0; --j) {
        BlockPos blockpos = (BlockPos) list1.get(j);
        Block block = worldIn.getBlockState(blockpos).getBlock();
        block.dropBlockAsItem(worldIn, blockpos, worldIn.getBlockState(blockpos), 0);
        worldIn.setBlockToAir(blockpos);
        --i;
        ablock[i] = block;
      }

      for (int k = list.size() - 1; k >= 0; --k) {
        BlockPos blockpos2 = (BlockPos) list.get(k);
        IBlockState iblockstate = worldIn.getBlockState(blockpos2);
        Block block1 = iblockstate.getBlock();
        block1.getMetaFromState(iblockstate);
        worldIn.setBlockToAir(blockpos2);
        blockpos2 = blockpos2.offset(enumfacing);
        worldIn.setBlockState(
            blockpos2,
            Blocks.piston_extension.getDefaultState().withProperty(FACING, direction),
            4);
        worldIn.setTileEntity(
            blockpos2, BlockPistonMoving.newTileEntity(iblockstate, direction, extending, false));
        --i;
        ablock[i] = block1;
      }

      BlockPos blockpos1 = pos.offset(direction);

      if (extending) {
        BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype =
            this.isSticky
                ? BlockPistonExtension.EnumPistonType.STICKY
                : BlockPistonExtension.EnumPistonType.DEFAULT;
        IBlockState iblockstate1 =
            Blocks.piston_head
                .getDefaultState()
                .withProperty(BlockPistonExtension.FACING, direction)
                .withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
        IBlockState iblockstate2 =
            Blocks.piston_extension
                .getDefaultState()
                .withProperty(BlockPistonMoving.FACING, direction)
                .withProperty(
                    BlockPistonMoving.TYPE,
                    this.isSticky
                        ? BlockPistonExtension.EnumPistonType.STICKY
                        : BlockPistonExtension.EnumPistonType.DEFAULT);
        worldIn.setBlockState(blockpos1, iblockstate2, 4);
        worldIn.setTileEntity(
            blockpos1, BlockPistonMoving.newTileEntity(iblockstate1, direction, true, false));
      }

      for (int l = list1.size() - 1; l >= 0; --l) {
        worldIn.notifyNeighborsOfStateChange((BlockPos) list1.get(l), ablock[i++]);
      }

      for (int i1 = list.size() - 1; i1 >= 0; --i1) {
        worldIn.notifyNeighborsOfStateChange((BlockPos) list.get(i1), ablock[i++]);
      }

      if (extending) {
        worldIn.notifyNeighborsOfStateChange(blockpos1, Blocks.piston_head);
        worldIn.notifyNeighborsOfStateChange(pos, this);
      }

      return true;
    }
  }
Exemplo n.º 24
0
  /** Called on both Client and Server when World#addBlockEvent is called */
  public boolean onBlockEventReceived(
      World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);

    if (!worldIn.isRemote) {
      boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

      if (flag && eventID == 1) {
        worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
        return false;
      }

      if (!flag && eventID == 0) {
        return false;
      }
    }

    if (eventID == 0) {
      if (!this.doMove(worldIn, pos, enumfacing, true)) {
        return false;
      }

      worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.out",
          0.5F,
          worldIn.rand.nextFloat() * 0.25F + 0.6F);
    } else if (eventID == 1) {
      TileEntity tileentity1 = worldIn.getTileEntity(pos.offset(enumfacing));

      if (tileentity1 instanceof TileEntityPiston) {
        ((TileEntityPiston) tileentity1).clearPistonTileEntity();
      }

      worldIn.setBlockState(
          pos,
          Blocks.piston_extension
              .getDefaultState()
              .withProperty(BlockPistonMoving.FACING, enumfacing)
              .withProperty(
                  BlockPistonMoving.TYPE,
                  this.isSticky
                      ? BlockPistonExtension.EnumPistonType.STICKY
                      : BlockPistonExtension.EnumPistonType.DEFAULT),
          3);
      worldIn.setTileEntity(
          pos,
          BlockPistonMoving.newTileEntity(
              this.getStateFromMeta(eventParam), enumfacing, false, true));

      if (this.isSticky) {
        BlockPos blockpos =
            pos.add(
                enumfacing.getFrontOffsetX() * 2,
                enumfacing.getFrontOffsetY() * 2,
                enumfacing.getFrontOffsetZ() * 2);
        Block block = worldIn.getBlockState(blockpos).getBlock();
        boolean flag1 = false;

        if (block == Blocks.piston_extension) {
          TileEntity tileentity = worldIn.getTileEntity(blockpos);

          if (tileentity instanceof TileEntityPiston) {
            TileEntityPiston tileentitypiston = (TileEntityPiston) tileentity;

            if (tileentitypiston.getFacing() == enumfacing && tileentitypiston.isExtending()) {
              tileentitypiston.clearPistonTileEntity();
              flag1 = true;
            }
          }
        }

        if (!flag1
            && block.getMaterial() != Material.air
            && canPush(block, worldIn, blockpos, enumfacing.getOpposite(), false)
            && (block.getMobilityFlag() == 0
                || block == Blocks.piston
                || block == Blocks.sticky_piston)) {
          this.doMove(worldIn, pos, enumfacing, false);
        }
      } else {
        worldIn.setBlockToAir(pos.offset(enumfacing));
      }

      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.in",
          0.5F,
          worldIn.rand.nextFloat() * 0.15F + 0.6F);
    }

    return true;
  }
Exemplo n.º 25
0
  public static ChangeBlockEvent.Place callBlockPlaceEvent(Event event) {
    if (!(event instanceof ChangeBlockEvent.Place)) {
      throw new IllegalArgumentException("Event is not a valid ChangeBlockEventPlace");
    }

    ChangeBlockEvent.Place spongeEvent = (ChangeBlockEvent.Place) event;

    if (spongeEvent.getCause().first(Player.class).isPresent()) {
      EntityPlayer player = (EntityPlayer) spongeEvent.getCause().first(Player.class).get();
      net.minecraft.world.World world = (net.minecraft.world.World) spongeEvent.getTargetWorld();

      if (spongeEvent.getTransactions().size() == 1) {
        BlockPos pos =
            VecHelper.toBlockPos(spongeEvent.getTransactions().get(0).getOriginal().getPosition());
        IBlockState state =
            (IBlockState) spongeEvent.getTransactions().get(0).getOriginal().getState();
        net.minecraftforge.common.util.BlockSnapshot blockSnapshot =
            new net.minecraftforge.common.util.BlockSnapshot(world, pos, state);
        IBlockState placedAgainst = Blocks.air.getDefaultState();
        if (StaticMixinHelper.packetPlayer != null
            && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) {
          C08PacketPlayerBlockPlacement packet =
              (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket;
          EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection());
          placedAgainst =
              blockSnapshot.world.getBlockState(blockSnapshot.pos.offset(facing.getOpposite()));
        }

        BlockEvent.PlaceEvent forgeEvent =
            new BlockEvent.PlaceEvent(blockSnapshot, placedAgainst, player);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
          spongeEvent.getTransactions().get(0).setValid(false);
        }
      } else { // multi
        Iterator<Transaction<BlockSnapshot>> iterator = spongeEvent.getTransactions().iterator();
        List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = new ArrayList<>();

        while (iterator.hasNext()) {
          Transaction<BlockSnapshot> transaction = iterator.next();
          Location<World> location = transaction.getOriginal().getLocation().get();
          IBlockState state = (IBlockState) transaction.getOriginal().getState();
          BlockPos pos =
              new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
          net.minecraftforge.common.util.BlockSnapshot blockSnapshot =
              new net.minecraftforge.common.util.BlockSnapshot(world, pos, state);
          blockSnapshots.add(blockSnapshot);
        }

        IBlockState placedAgainst = Blocks.air.getDefaultState();
        if (StaticMixinHelper.packetPlayer != null
            && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) {
          C08PacketPlayerBlockPlacement packet =
              (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket;
          EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection());
          placedAgainst =
              blockSnapshots
                  .get(0)
                  .world
                  .getBlockState(blockSnapshots.get(0).pos.offset(facing.getOpposite()));
        }

        BlockEvent.MultiPlaceEvent forgeEvent =
            new BlockEvent.MultiPlaceEvent(blockSnapshots, placedAgainst, player);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
          while (iterator.hasNext()) {
            iterator.next().setValid(false);
          }
        }
      }
    }
    return spongeEvent;
  }
Exemplo n.º 26
0
 /** Check whether this Block can be placed on the given side */
 public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
   return func_181088_a(worldIn, pos, side.getOpposite());
 }
Exemplo n.º 27
0
 private void notifyNeighbors(World worldIn, BlockPos pos, EnumFacing facing) {
   worldIn.notifyNeighborsOfStateChange(pos, this);
   worldIn.notifyNeighborsOfStateChange(pos.offset(facing.getOpposite()), this);
 }