cpw.mods.fml.common.registry.GameData Java Examples

The following examples show how to use cpw.mods.fml.common.registry.GameData. 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: TileStickyJar.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readCustomNBT(NBTTagCompound compound) {
    String parentType = compound.getString("parentType");
    if(parentType.length() > 0) {
        Block block = GameData.getBlockRegistry().getObject(parentType);
        if(block != null && compound.hasKey("parent") && compound.hasKey("parentMetadata")) {
            NBTTagCompound data = compound.getCompoundTag("parent");
            int metadata = compound.getInteger("parentMetadata");
            TileEntity tile = block.createTileEntity(getWorldObj(), metadata);
            if(tile instanceof TileJarFillable) {
                placedOn = ForgeDirection.getOrientation(compound.getInteger("placedOn"));
                tile.readFromNBT(data);
                init((TileJarFillable) tile, block, metadata, placedOn);
            }
        }
    }

    if(!isValid() && !getWorldObj().isRemote) {
        getWorldObj().setBlockToAir(xCoord, yCoord, zCoord);
    }
}
 
Example #2
Source File: ModSubstitutions.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void preInit() {
        if(ModConfig.enableAdditionalNodeTypes) {
            try {
                ItemBlock item = (ItemBlock) Item.getItemFromBlock(ConfigBlocks.blockAiry);

                item.field_150939_a = RegisteredBlocks.blockNode;

                //Hacky way
                FMLControlledNamespacedRegistry<Block> registry = GameData.getBlockRegistry();
                registry.underlyingIntegerMap.field_148749_a.put(RegisteredBlocks.blockNode, Block.getIdFromBlock(ConfigBlocks.blockAiry));
                registry.underlyingIntegerMap.field_148748_b.set(Block.getIdFromBlock(ConfigBlocks.blockAiry), RegisteredBlocks.blockNode);
                ((BiMap)registry.field_148758_b).forcePut(RegisteredBlocks.blockNode, registry.field_148758_b.get(ConfigBlocks.blockAiry));

                registry.underlyingIntegerMap.field_148749_a.remove(ConfigBlocks.blockAiry);

                ConfigBlocks.blockAiry = RegisteredBlocks.blockNode;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
}
 
Example #3
Source File: MovementDataProviderDefault.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void readMovementInfo(IMovingBlock block, NBTTagCompound tag) {

    block.setBlock(GameData.getBlockRegistry().getObject(tag.getString("block")));
    block.setMetadata(tag.getInteger("metadata"));
    TileEntity te = block.getTileEntity();

    if (tag.hasKey("data") && (te != null || block.getBlock() instanceof ITileEntityProvider)) {
        if (te == null) {
            te = ((ITileEntityProvider) block.getBlock()).createNewTileEntity(FakeWorld.getFakeWorld((MovingBlock) block),
                    block.getMetadata());
            System.out.println("creating!");
        }
        if (te != null) {
            te.readFromNBT(tag.getCompoundTag("data"));
            block.setTileEntity(te);
        }
    }

    ((MovingBlock) block).setRenderList(-1);
}
 
Example #4
Source File: ProgWidgetItemFilter.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack loadItemStackByName(NBTTagCompound tag){
    Item item = GameData.getItemRegistry().getObject(tag.getString("id"));
    if(item == null) return null;
    ItemStack stack = new ItemStack(item, tag.getByte("Count"), tag.getShort("Damage"));
    if(stack.getItemDamage() < 0) stack.setItemDamage(0);

    if(tag.hasKey("tag", 10)) {
        stack.setTagCompound(tag.getCompoundTag("tag"));
    }
    return stack;
}
 
Example #5
Source File: ProgWidgetItemFilter.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private static void saveItemStackByName(ItemStack stack, NBTTagCompound tag){
    tag.setString("id", GameData.getItemRegistry().getNameForObject(stack.getItem()));
    tag.setByte("Count", (byte)stack.stackSize);
    tag.setShort("Damage", (short)stack.getItemDamage());
    if(stack.hasTagCompound()) {
        tag.setTag("tag", stack.getTagCompound());
    }
}
 
Example #6
Source File: AmadronOffer.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private int getObjectHashCode(Object o){
    if(o instanceof FluidStack) {
        return o.hashCode();
    } else {
        ItemStack stack = (ItemStack)o;
        return GameData.getItemRegistry().getNameForObject(stack.getItem()).hashCode() + stack.stackSize * 19;
    }
}
 
Example #7
Source File: AmadronOffer.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public JsonObject toJson(){
    JsonObject object = new JsonObject();

    JsonObject inputObject = new JsonObject();
    if(input instanceof ItemStack) {
        inputObject.addProperty("id", GameData.getItemRegistry().getNameForObject(((ItemStack)input).getItem()));
        inputObject.addProperty("damage", ((ItemStack)input).getItemDamage());
        inputObject.addProperty("amount", ((ItemStack)input).stackSize);
    } else {
        inputObject.addProperty("id", ((FluidStack)input).getFluid().getName());
        inputObject.addProperty("amount", ((FluidStack)input).amount);
    }
    object.add("input", inputObject);

    JsonObject outputObject = new JsonObject();
    if(output instanceof ItemStack) {
        outputObject.addProperty("id", GameData.getItemRegistry().getNameForObject(((ItemStack)output).getItem()));
        outputObject.addProperty("damage", ((ItemStack)output).getItemDamage());
        outputObject.addProperty("amount", ((ItemStack)output).stackSize);
    } else {
        outputObject.addProperty("id", ((FluidStack)output).getFluid().getName());
        outputObject.addProperty("amount", ((FluidStack)output).amount);
    }
    object.add("output", outputObject);

    return object;
}
 
Example #8
Source File: Hydraulicraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static void registrarHandling(IHydraulicraftRegistrar registrar){
    registrar.registerTrolley(new TrolleyPlasticPlants());

    ItemStack cropsTrolly = registrar.getTrolleyItem("plasticPlants");
    cropsTrolly.stackSize = 4;

    Block pressureCore = GameData.getBlockRegistry().getObject(ModIds.HC + ":LPBlockCore");
    Block pressureWall = GameData.getBlockRegistry().getObject(ModIds.HC + ":hydraulicPressureWall");
    Block hydraulicPiston = GameData.getBlockRegistry().getObject(ModIds.HC + ":hydraulicPiston");

    GameRegistry.addRecipe(new ShapedOreRecipe(cropsTrolly, true, "-P-", "WCW", "-H-", 'C', new ItemStack(pressureCore, 1, 1), 'W', pressureWall, 'H', Itemss.turbineRotor, 'P', hydraulicPiston));
}
 
Example #9
Source File: ModItems.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Item item, int meta) {
    String name = GameData.getItemRegistry().getNameForObject(item);
    if (name == null)
        return null;

    return new UniqueMetaIdentifier(name, meta);
}
 
Example #10
Source File: ModBlocks.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Block block, int meta) {
    String name = GameData.getBlockRegistry().getNameForObject(block);
    if (name == null) {
        FMLLog.log(GardenCore.MOD_ID, Level.WARN, "Tried to make a UniqueMetaIdentifier from an invalid block");
        return null;
    }

    return new UniqueMetaIdentifier(name, meta);
}
 
Example #11
Source File: ModItems.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Item item, int meta) {
    String name = GameData.getItemRegistry().getNameForObject(item);
    if (name == null)
        return null;

    return new UniqueMetaIdentifier(name, meta);
}
 
Example #12
Source File: UniqueMetaIdentifier.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier createFor (Block block) {
    if (block == null)
        return null;

    String name = GameData.getBlockRegistry().getNameForObject(block);
    return new UniqueMetaIdentifier(name);
}
 
Example #13
Source File: UniqueMetaIdentifier.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier createFor (Block block, int meta) {
    if (block == null)
        return null;

    String name = GameData.getBlockRegistry().getNameForObject(block);
    return new UniqueMetaIdentifier(name, meta);
}
 
Example #14
Source File: UniqueMetaIdentifier.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier createFor (ItemStack itemStack) {
    if (itemStack.getItem() == null)
        return null;

    String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem());
    return new UniqueMetaIdentifier(name, itemStack.getItemDamage());
}
 
Example #15
Source File: ModBlocks.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Block block, int meta) {
    String name = GameData.getBlockRegistry().getNameForObject(block);
    if (name == null) {
        FMLLog.log(GardenContainers.MOD_ID, Level.WARN, "Tried to make a UniqueMetaIdentifier from an invalid block");
        return null;
    }

    return new UniqueMetaIdentifier(name, meta);
}
 
Example #16
Source File: ModBlocks.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Block block, int meta) {
    String name = GameData.getBlockRegistry().getNameForObject(block);
    if (name == null) {
        FMLLog.log(GardenTrees.MOD_ID, Level.WARN, "Tried to make a UniqueMetaIdentifier from an invalid block");
        return null;
    }

    return new UniqueMetaIdentifier(name, meta);
}
 
Example #17
Source File: TileEntityWoodProxy.java    From GardenCollection with MIT License 5 votes vote down vote up
public static Block getBlockFromComposedMetadata (int metadata) {
    if (metadata >= 16)
        return GameData.blockRegistry.get(metadata & 0xFFF);
    else if (metadata < 4)
        return Blocks.log;
    else if (metadata < 8)
        return Blocks.log2;
    else
        return null;
}
 
Example #18
Source File: MovementDataProviderDefault.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeMovementInfo(IMovingBlock block, NBTTagCompound tag) {

    tag.setString("block", GameData.getBlockRegistry().getNameForObject(block.getBlock()));
    tag.setInteger("metadata", block.getMetadata());
    NBTTagCompound t = null;
    if (block.getTileEntity() != null)
        block.getTileEntity().writeToNBT(t = new NBTTagCompound());
    if (t != null)
        tag.setTag("data", t);
}
 
Example #19
Source File: ItemFingerprint.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
public ItemFingerprint(ItemStack stack) {
	String itemId = GameData.getItemRegistry().getNameForObject(stack.getItem());
	this.id = new UniqueIdentifier(itemId);
	this.damage = stack.getItemDamage();

	NBTTagCompound tag = stack.getTagCompound();
	this.nbtHash = tag != null? ItemUtils.getNBTHash(tag) : null;
}
 
Example #20
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 #21
Source File: TileStickyJar.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeCustomNBT(NBTTagCompound compound) {
    if(isValid()) {
        compound.setString("parentType", GameData.getBlockRegistry().getNameForObject(parentBlock));
        compound.setInteger("parentMetadata", parentMetadata);

        syncToParent();

        NBTTagCompound data = new NBTTagCompound();
        parent.writeToNBT(data);
        compound.setTag("parent", data);

        compound.setInteger("placedOn", placedOn.ordinal());
    }
}
 
Example #22
Source File: ModBlocks.java    From GardenCollection with MIT License 4 votes vote down vote up
public static String getQualifiedName (Block block) {
    return GameData.getBlockRegistry().getNameForObject(block);
}
 
Example #23
Source File: TileEntityBlockMateralProxy.java    From GardenCollection with MIT License 4 votes vote down vote up
public int composeMetadata (Block block, int meta) {
    int id = GameData.getBlockRegistry().getId(block);
    return ((id & 0xFFF) << 4) | (meta & 0xF);
}
 
Example #24
Source File: TileEntityBlockMateralProxy.java    From GardenCollection with MIT License 4 votes vote down vote up
public Block getBlockFromComposedMetadata (int metadata) {
    if (metadata >= 16)
        return GameData.getBlockRegistry().getObjectById((metadata >> 4) & 0xFFF);

    return getBlockFromStandardMetadata(metadata);
}
 
Example #25
Source File: ModItems.java    From GardenCollection with MIT License 4 votes vote down vote up
public static UniqueMetaIdentifier getUniqueMetaID (Item item, int meta) {
    String name = GameData.getItemRegistry().getNameForObject(item);
    return new UniqueMetaIdentifier(name, meta);
}
 
Example #26
Source File: ModBlocks.java    From GardenCollection with MIT License 4 votes vote down vote up
public static String getQualifiedName (Block block) {
    return GameData.getBlockRegistry().getNameForObject(block);
}
 
Example #27
Source File: ModBlocks.java    From GardenCollection with MIT License 4 votes vote down vote up
public static String getQualifiedName (Block block) {
    return GameData.getBlockRegistry().getNameForObject(block);
}
 
Example #28
Source File: TileEntityWoodProxy.java    From GardenCollection with MIT License 4 votes vote down vote up
public static int composeMetadata (Block block, int meta) {
    int id = GameData.blockRegistry.getId(block);
    return (id & 0xFFF) | ((meta & 0xF) << 12);
}
 
Example #29
Source File: ModBlocks.java    From GardenCollection with MIT License 4 votes vote down vote up
public static String getQualifiedName (Block block) {
    return GameData.getBlockRegistry().getNameForObject(block);
}
 
Example #30
Source File: ItemFingerprint.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
public ItemFingerprint(Item item, int damage, NBTTagCompound tag) {
	String itemId = GameData.getItemRegistry().getNameForObject(item);
	this.id = new UniqueIdentifier(itemId);
	this.damage = damage;
	this.nbtHash = tag != null? ItemUtils.getNBTHash(tag) : null;
}