Java Code Examples for net.minecraft.tileentity.TileEntity#isInvalid()

The following examples show how to use net.minecraft.tileentity.TileEntity#isInvalid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileItemSource.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected IItemHandler computeItemHandler() {
    if (!world.isBlockLoaded(accessedBlockPos)) {
        //we handle unloaded blocks as empty item handlers
        //so when they are loaded, they are refreshed and handled correctly
        return EmptyHandler.INSTANCE;
    }
    //use cached tile entity as long as it's valid and has same position (just in case of frames etc)
    TileEntity tileEntity = cachedTileEntity.get();
    if (tileEntity == null || tileEntity.isInvalid() || !tileEntity.getPos().equals(accessedBlockPos)) {
        tileEntity = world.getTileEntity(accessedBlockPos);
        if (tileEntity == null) {
            //if tile entity doesn't exist anymore, we are invalid now
            //return null which will be handled as INVALID
            return null;
        }
        //update cached tile entity
        this.cachedTileEntity = new WeakReference<>(tileEntity);
    }
    //fetch capability from tile entity
    //if it returns null, item handler info will be removed
    //block should emit block update once it obtains capability again,
    //so handler info will be recreated accordingly
    return tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, accessSide.getOpposite());
}
 
Example 2
Source File: BlockPassengerChair.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity passengerChair = worldIn.getTileEntity(pos);
    if (passengerChair instanceof TileEntityPassengerChair && !passengerChair.isInvalid()) {
        ((TileEntityPassengerChair) passengerChair).onBlockBroken(state);
    }
    super.breakBlock(worldIn, pos, state);
}
 
Example 3
Source File: MixinChunk.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private void removeTileEntityFromIndex(BlockPos pos, int yIndex) {
    if (tileEntitesByExtendedData[yIndex] == null) {
        tileEntitesByExtendedData[yIndex] = new ArrayList<TileEntity>();
    }
    Iterator<TileEntity> tileEntitiesIterator = tileEntitesByExtendedData[yIndex].iterator();
    while (tileEntitiesIterator.hasNext()) {
        TileEntity tile = tileEntitiesIterator.next();
        if (tile.getPos().equals(pos) || tile.isInvalid()) {
            tileEntitiesIterator.remove();
        }
    }
}
 
Example 4
Source File: GT_MetaTileEntity_WorldAccelerator.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
private boolean isTEBlackListed( TileEntity pTile )
{
  if( pTile == null ) {
      return true; // Obvious
  }
  if( !pTile.canUpdate() ) {
      return true; // Skip if TE can't update at all
  }
  if( pTile.isInvalid() ) {
      return true; // Obvious
  }   
  
  String tSimpleClassName = pTile.getClass().getSimpleName().toLowerCase();
  String tCanonicalName = pTile.getClass().getCanonicalName().toLowerCase();
  if( tSimpleClassName.contains( "conduit" ) || tSimpleClassName.contains( "wire" ) || tSimpleClassName.contains( "cable" ) ) {
      return true;
  }
  if( tCanonicalName.contains( "appeng" ) || tCanonicalName.contains( "gregtech" ) ) // Don't accelerate ANY gregtech machines
  {
      return true;
  }
  if (tSimpleClassName.contains( "solar" )|| tCanonicalName.contains( "solar" ))// Don't accelerate ANY solars
  {	
  	return true;
  }
  	
  for( String tS : MainRegistry.CoreConfig.BlacklistedTileEntiyClassNames )
  {
    if( tCanonicalName.equalsIgnoreCase( tS ) ) {
        return true;
    }
  }

  return GT_MetaTileEntity_WorldAccelerator._mBlacklistedTiles.stream()
          .map(Class::getCanonicalName)
          .map(String::toLowerCase)
          .anyMatch(tCanonicalName::equalsIgnoreCase);
}
 
Example 5
Source File: AdapterWorldInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
private static IWorldPosProvider getProvider(IInventory target) {
	if (target instanceof IWorldPosProvider) return (IWorldPosProvider)target;
	if (target instanceof TileEntity) {
		final TileEntity te = (TileEntity)target;
		return new IWorldPosProvider() {

			@Override
			public boolean isValid() {
				return !te.isInvalid();
			}

			@Override
			public World getWorld() {
				return te.getWorldObj();
			}

			@Override
			public int getX() {
				return te.xCoord;
			}

			@Override
			public int getY() {
				return te.yCoord;
			}

			@Override
			public int getZ() {
				return te.zCoord;
			}
		};
	}

	throw new IllegalArgumentException("Invalid target object " + String.valueOf(target));
}
 
Example 6
Source File: AbstractPair.java    From NEI-Integration with MIT License 4 votes vote down vote up
protected TileEntity getPairAt(WorldCoordinate coord) {
    if (!pairings.contains(coord))
        return null;

    int x = coord.x;
    int y = coord.y;
    int z = coord.z;

    if (!IS_BUKKIT) {
        TileEntity cacheTarget = tileCache.get(coord);
        if (cacheTarget != null) {
            if (cacheTarget.isInvalid() || cacheTarget.xCoord != x || cacheTarget.yCoord != y || cacheTarget.zCoord != z)
                tileCache.remove(coord);
            else if (isValidPair(coord, cacheTarget))
                return cacheTarget;
        }
    }

    if (y < 0) {
        clearPairing(coord);
        return null;
    }

    World world = tile.getWorldObj();
    if (!world.blockExists(x, y, z))
        return null;

    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);
    if (!block.hasTileEntity(meta)) {
        pairingsToTest.add(coord);
        return null;
    }

    TileEntity target = world.getTileEntity(x, y, z);
    if (target != null && !isValidPair(coord, target)) {
        pairingsToTest.add(coord);
        return null;
    }

    if (!IS_BUKKIT && target != null) {
        tileCache.put(coord, target);
    }

    return target;
}
 
Example 7
Source File: BlockEnderUtilitiesTileEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isTileEntityValid(TileEntity te)
{
    return te != null && te.isInvalid() == false;
}
 
Example 8
Source File: WorldUtils.java    From OpenModsLib with MIT License 4 votes vote down vote up
public static boolean isTileEntityValid(TileEntity te) {
	if (te.isInvalid()) return false;

	final World world = te.getWorld();
	return (world != null)? world.isBlockLoaded(te.getPos()) : false;
}