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

The following examples show how to use net.minecraft.tileentity.TileEntity#getClass() . 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: ItemPickupManager.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (world.isRemote == false)
    {
        TileEntity te = world.getTileEntity(pos);

        // When sneak-right-clicking on an inventory or an Ender Chest, and the installed Link Crystal is a block type crystal,
        // then bind the crystal to the block clicked on.
        if (player.isSneaking() && te != null &&
            (te.getClass() == TileEntityEnderChest.class || te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)))
        {
            ItemStack stack = player.getHeldItem(hand);
            UtilItemModular.setTarget(stack, player,pos, side, hitX, hitY, hitZ, false, false);
        }
    }

    return EnumActionResult.SUCCESS;
}
 
Example 2
Source File: ItemEnderSword.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);
    TileEntity te = world.getTileEntity(pos);

    // When sneak-right-clicking on an inventory or an Ender Chest, and the installed Link Crystal is a block type crystal,
    // then bind the crystal to the block clicked on.
    if (player.isSneaking() && te != null &&
        (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side) || te.getClass() == TileEntityEnderChest.class) &&
        UtilItemModular.getSelectedModuleTier(stack, ModuleType.TYPE_LINKCRYSTAL) == ItemLinkCrystal.TYPE_BLOCK)
    {
        if (world.isRemote == false)
        {
            UtilItemModular.setTarget(stack, player, pos, side, hitX, hitY, hitZ, false, false);
        }

        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.PASS;
}
 
Example 3
Source File: DriverOpenPeripheral.java    From OpenPeripheral with MIT License 6 votes vote down vote up
@Override
public boolean worksWith(World world, int x, int y, int z) {
	final TileEntity te = world.getTileEntity(x, y, z);
	if (te == null) return false;

	final Class<?> cls = te.getClass();

	Boolean result = cache.get(cls);

	if (result == null) {
		result = shouldProvide(cls);
		cache.put(cls, result);
	}

	return result;
}
 
Example 4
Source File: EntityGroup.java    From TickDynamic with MIT License 5 votes vote down vote up
private List<Class> loadTilesByName(String name) {
	FMLControlledNamespacedRegistry<Block> blockRegistry = GameData.getBlockRegistry();
	Block block = blockRegistry.getRaw(name);
	if(block == null)
		return null;

	//Get TileEntities for every metadata
	TileEntity currentTile;
	Class prevTile = null;
	List<Class> tileClassList = new ArrayList<Class>(16);
	for(byte b = 0; b < 16; b++)
	{
		if(block.hasTileEntity(b))
		{
			//Might throw an exception while creating TileEntity, especially at initial load of global groups
			try {
				currentTile = block.createTileEntity(world, b);
			} catch(Exception e)
			{
				if(mod.debug)
					System.out.println("Exception while loading Tile for " + name + ":\n" + e.getMessage());
				currentTile = null;
			}
			
			Class cls = currentTile.getClass();
			if(currentTile != null && cls != prevTile)
			{
				
				if(!tileClassList.contains(cls))
					tileClassList.add(currentTile.getClass());
			}
			prevTile = cls;
		}
	}
	
	return tileClassList;
}
 
Example 5
Source File: TilePipe.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void onPlaced() {

		for(EnumFacing dir : EnumFacing.values()) {
			TileEntity tile = world.getTileEntity(getPos().offset(dir));


			if(tile != null) {
				if(tile instanceof TilePipe && tile.getClass() == this.getClass()) {
					TilePipe pipe = (TilePipe)tile;
					if(this.destroyed)
						continue;

					if(isInitialized() && pipe.isInitialized() && pipe.getNetworkID() != networkID)
						getNetworkHandler().mergeNetworks(networkID,  pipe.getNetworkID());
					else if(!isInitialized() && pipe.isInitialized()) {
						initialize(pipe.getNetworkID());
					}
					connectedSides[dir.ordinal()] = true;
				}
			}
		}


		if(!isInitialized()) {
			initialize(getNetworkHandler().getNewNetworkID());
		}

		linkSystems();
	}
 
Example 6
Source File: ItemEnderBag.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    TileEntity te = world.getTileEntity(pos);

    if (player.isSneaking() && te != null && te.getClass() == TileEntityEnderChest.class)
    {
        return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
    }

    return EnumActionResult.PASS;
}
 
Example 7
Source File: BasicConnectionProfile.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public boolean isAttachedNeighbor (IBlockAccess blockAccess, int x, int y, int z, int nx, int ny, int nz) {
    if (y != ny || Math.abs(nx - x) > 1 || Math.abs(nz - z) > 1)
        return false;

    Block sBlock = blockAccess.getBlock(x, y, z);
    Block nBlock = blockAccess.getBlock(nx, ny, nz);
    if (sBlock != nBlock)
        return false;

    int sData = blockAccess.getBlockMetadata(x, y, z);
    int nData = blockAccess.getBlockMetadata(nx, ny, nz);
    if (sData != nData)
        return false;

    TileEntity sEntity = blockAccess.getTileEntity(x, y, z);
    TileEntity nEntity = blockAccess.getTileEntity(nx, ny, nz);
    if (sEntity == null || nEntity == null || sEntity.getClass() != nEntity.getClass())
        return false;

    if (!(sEntity instanceof TileEntityGarden))
        return false;

    /*TileEntityGarden nGarden = (TileEntityGarden) nEntity;
    if ((substrate == null || nGarden.substrate == null) && substrate != nGarden.substrate)
        return false;

    if (substrate != null) {
        if (substrate.getItem() != nGarden.substrate.getItem() || substrate.getItemDamage() != nGarden.substrate.getItemDamage())
            return false;
    }*/

    return true;
}
 
Example 8
Source File: TileRef.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public TileRef( TileEntity gte ) {
	super( gte.xCoord, gte.yCoord, gte.zCoord );
	TileEntity te = gte;
	myType = gte.getClass();
	wasGrid = te instanceof IGridTileEntity;
	w = te.worldObj;
	if ( te.worldObj == null )
		throw new RuntimeException("Tile has no world.");
}
 
Example 9
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public BlockState getState() {
    Material material = getType();

    // Kettle start - if null, check for TE that implements IInventory (cauldron stuff)
    if (material == null) {
        TileEntity te = ((CraftWorld) this.getWorld()).getHandle().getTileEntity(new BlockPos(this.getX(), this.getY(), this.getZ()));
        if (te != null && te instanceof IInventory) {
            // In order to allow plugins to properly grab the container location, we must pass a class that extends CraftBlockState and implements InventoryHolder.
            // Note: This will be returned when TileEntity.getOwner() is called
            return new CraftCustomContainer(this);
        }
        // pass default state
        return new CraftBlockState(this);
    }
    // Kettle end

    switch (material) {
        case SIGN:
        case SIGN_POST:
        case WALL_SIGN:
            return new CraftSign(this);
        case CHEST:
        case TRAPPED_CHEST:
            return new CraftChest(this);
        case BURNING_FURNACE:
        case FURNACE:
            return new CraftFurnace(this);
        case DISPENSER:
            return new CraftDispenser(this);
        case DROPPER:
            return new CraftDropper(this);
        case END_GATEWAY:
            return new CraftEndGateway(this);
        case HOPPER:
            return new CraftHopper(this);
        case MOB_SPAWNER:
            return new CraftCreatureSpawner(this);
        case NOTE_BLOCK:
            return new CraftNoteBlock(this);
        case JUKEBOX:
            return new CraftJukebox(this);
        case BREWING_STAND:
            return new CraftBrewingStand(this);
        case SKULL:
            return new CraftSkull(this);
        case COMMAND:
        case COMMAND_CHAIN:
        case COMMAND_REPEATING:
            return new CraftCommandBlock(this);
        case BEACON:
            return new CraftBeacon(this);
        case BANNER:
        case WALL_BANNER:
        case STANDING_BANNER:
            return new CraftBanner(this);
        case FLOWER_POT:
            return new CraftFlowerPot(this);
        case STRUCTURE_BLOCK:
            return new CraftStructureBlock(this);
        case WHITE_SHULKER_BOX:
        case ORANGE_SHULKER_BOX:
        case MAGENTA_SHULKER_BOX:
        case LIGHT_BLUE_SHULKER_BOX:
        case YELLOW_SHULKER_BOX:
        case LIME_SHULKER_BOX:
        case PINK_SHULKER_BOX:
        case GRAY_SHULKER_BOX:
        case SILVER_SHULKER_BOX:
        case CYAN_SHULKER_BOX:
        case PURPLE_SHULKER_BOX:
        case BLUE_SHULKER_BOX:
        case BROWN_SHULKER_BOX:
        case GREEN_SHULKER_BOX:
        case RED_SHULKER_BOX:
        case BLACK_SHULKER_BOX:
            return new CraftShulkerBox(this);
        case ENCHANTMENT_TABLE:
            return new CraftEnchantingTable(this);
        case ENDER_CHEST:
            return new CraftEnderChest(this);
        case DAYLIGHT_DETECTOR:
        case DAYLIGHT_DETECTOR_INVERTED:
            return new CraftDaylightDetector(this);
        case REDSTONE_COMPARATOR_OFF:
        case REDSTONE_COMPARATOR_ON:
            return new CraftComparator(this);
        case BED_BLOCK:
            return new CraftBed(this);
        default:
            TileEntity tileEntity = chunk.getCraftWorld().getTileEntityAt(x, y, z);
            if (tileEntity != null) {
                // block with unhandled TileEntity:
                return new CraftBlockEntityState<TileEntity>(this, (Class<TileEntity>) tileEntity.getClass());
            } else {
                // Block without TileEntity:
                return new CraftBlockState(this);
            }
    }
}
 
Example 10
Source File: CauldronHooks.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static boolean canTileEntityTick(TileEntity tileEntity, World world)
{
    if (tileEntity == null || world.tileentityConfig == null) return false;
    if (MinecraftServer.tileEntityConfig.skipTileEntityTicks.getValue())
    {
        TileEntityCache teCache = tileEntityCache.get(tileEntity.getClass());
        if (teCache == null)
        {
            String teConfigPath = tileEntity.getClass().getName().replace(".", "-");
            teConfigPath = teConfigPath.replaceAll("[^A-Za-z0-9\\-]", ""); // Fix up odd class names to prevent YAML errors
            teCache = new TileEntityCache(tileEntity.getClass(), world.getWorldInfo().getWorldName().toLowerCase(), teConfigPath, world.tileentityConfig.getBoolean(teConfigPath + ".tick-no-players", false), world.tileentityConfig.getInt(teConfigPath + ".tick-interval", 1));
            tileEntityCache.put(tileEntity.getClass(), teCache);
        }

        // Tick with no players near?
        if (!teCache.tickNoPlayers && !world.isActiveBlockCoord(tileEntity.xCoord, tileEntity.zCoord))
        {
            return false;
        }

        // Skip tick interval
        if (teCache.tickInterval > 0 && (world.getWorldInfo().getWorldTotalTime() % teCache.tickInterval == 0L))
        {
            return true;
        }
        
    	if(world.chunkProvider instanceof ChunkProviderServer) // Thermos - allow the server to tick tiles that are trying to unload
    	{
    		ChunkProviderServer cps = ((ChunkProviderServer)world.chunkProvider);
    		if(cps.chunksToUnload.contains(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4))
    		{
    			Chunk c = cps.getChunkIfLoaded(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4);
    			if(c != null)
    			{
    				if(c.lastAccessedTick < 2L)
    				{
    					return true;
    				}
    			}
    		}
    	}
    	
        return false;
    }
    return true;
}
 
Example 11
Source File: BlockActiveState.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public BlockActiveState(Material mat, TileEntity tile) {
	super(mat);
	tileClass = tile == null ? null : tile.getClass();
}
 
Example 12
Source File: ItemEnderTool.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);
    TileEntity te = world.getTileEntity(pos);

    // When sneak-right-clicking on an inventory or an Ender Chest, and the installed Link Crystal is a block type crystal,
    // then bind the crystal to the block clicked on.
    if (player.isSneaking() && te != null &&
        (te.getClass() == TileEntityEnderChest.class || te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
        && UtilItemModular.getSelectedModuleTier(stack, ModuleType.TYPE_LINKCRYSTAL) == ItemLinkCrystal.TYPE_BLOCK)
    {
        if (world.isRemote == false)
        {
            UtilItemModular.setTarget(stack, player,pos, side, hitX, hitY, hitZ, false, false);
        }

        return EnumActionResult.SUCCESS;
    }
    // Hoe
    else if (ToolType.fromStack(stack) == ToolType.HOE)
    {
        if (world.isRemote == false)
        {
            if (PowerStatus.fromStack(stack) == PowerStatus.POWERED)
            {
                // Didn't till any soil; try to plant stuff from the player inventory or a remote inventory
                if (this.useHoeArea(stack, player, world, pos, side, 1, 1) == false)
                {
                    this.useHoeToPlantArea(stack, player, hand, world, pos, side, hitX, hitY, hitZ, 1, 1);
                }
            }
            else
            {
                // Didn't till any soil; try to plant stuff from the player inventory or a remote inventory
                if (this.useHoe(stack, player, world, pos, side) == false)
                {
                    this.useHoeToPlant(stack, player, hand, world, pos, side, hitX, hitY, hitZ);
                }
            }
        }

        return EnumActionResult.SUCCESS;
    }
    // Try to place a block from the slot right to the currently selected tool (or from slot 1 if tool is in slot 9)
    else
    {
        return this.placeBlock(stack, player, hand, world, pos, side, hitX, hitY, hitZ);
    }
}
 
Example 13
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);
    TileEntity te = world.getTileEntity(pos);

    if (te != null && (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side) || te.getClass() == TileEntityEnderChest.class))
    {
        return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
    }

    Mode mode = Mode.getMode(stack);

    if (mode.hasTwoPlacableCorners())
    {
        if (world.isRemote == false)
        {
            if (mode == Mode.REPLACE_3D && player.isSneaking() && WandOption.BIND_MODE.isEnabled(stack, mode))
            {
                this.setSelectedFixedBlockType(stack, player, world, pos, true);
            }
            else
            {
                BlockPosEU posEU = new BlockPosEU(player.isSneaking() ? pos : pos.offset(side), world.provider.getDimension(), side);
                this.setPosition(posEU, POS_END, stack, player);
            }
        }

        return EnumActionResult.SUCCESS;
    }

    // Don't allow targeting the top face of blocks while sneaking
    // This should make sneak building a platform a lot less annoying
    if (world.isRemote == false && (player.isSneaking() == false || side != EnumFacing.UP || mode == Mode.REPLACE))
    {
        // Don't offset the position in Replace mode
        if (mode != Mode.REPLACE)
        {
            pos = pos.offset(side);
        }

        return this.useWand(stack, world, player, new BlockPosEU(pos, world.provider.getDimension(), side));
    }

    return EnumActionResult.SUCCESS;
}