@Override public BlockState getBlock(BlockVector3 position) { World world = getWorld(); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState mcState = world.getBlockState(pos); BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getNameForObject(mcState.getBlock()).toString()); return blockType.getState(adaptProperties(blockType, mcState.getProperties())); }
@Nullable @Override public String getName(BlockType blockType) { return Block.REGISTRY.getObject(new ResourceLocation(blockType.getId())).getLocalizedName(); }
@EventHandler public void serverAboutToStart(FMLServerAboutToStartEvent event) { if (this.platform != null) { logger.warn("FMLServerStartingEvent occurred when FMLServerStoppingEvent hasn't"); WorldEdit.getInstance().getPlatformManager().unregister(platform); } this.platform = new ForgePlatform(this); WorldEdit.getInstance().getPlatformManager().register(platform); if (Loader.isModLoaded("sponge")) { this.provider = new ForgePermissionsProvider.SpongePermissionsProvider(); } else { this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform); } for (ResourceLocation name : Block.REGISTRY.getKeys()) { String nameStr = name.toString(); if (!BlockType.REGISTRY.keySet().contains(nameStr)) { BlockTypes.register(new BlockType(nameStr)); } } for (ResourceLocation name : Item.REGISTRY.getKeys()) { String nameStr = name.toString(); if (!ItemType.REGISTRY.keySet().contains(nameStr)) { ItemTypes.register(new ItemType(nameStr)); } } }
public static Block findBlock(@Nonnull String mod, @Nonnull String blockName) { final ResourceLocation name = new ResourceLocation(mod, blockName); if (Block.REGISTRY.containsKey(name)) { return Block.REGISTRY.getObject(name); } return null; }
final Set<String> names = mapping.getKeySet(); for (final String name : names) { oldToNew.put(mapping.getShort(name), (short) Block.REGISTRY.getIDForObject(Block.REGISTRY.getObject(new ResourceLocation(name)))); final Block block = Block.REGISTRY.getObjectById(blockID); pos.set(x, y, z); try { schematic.setBlockState(pos, blockState); } catch (final Exception e) { Reference.logger.error("Could not set block state at {} to {} with metadata {}", pos, Block.REGISTRY.getNameForObject(block), meta, e);
public static List<TippedArrowRecipeWrapper> getTippedArrowRecipes() { List<TippedArrowRecipeWrapper> recipes = new ArrayList<>(); for (ResourceLocation potionTypeResourceLocation : PotionType.REGISTRY.getKeys()) { PotionType potionType = PotionType.REGISTRY.getObject(potionTypeResourceLocation); TippedArrowRecipeWrapper recipe = new TippedArrowRecipeWrapper(potionType); recipes.add(recipe); } return recipes; }
final IBlockState blockState = schematic.getBlockState(pos.set(x, y, z)); final Block block = blockState.getBlock(); final int blockId = Block.REGISTRY.getIDForObject(block); localBlocks[index] = (byte) blockId; localMetadata[index] = (byte) block.getMetaFromState(blockState); final String name = String.valueOf(Block.REGISTRY.getNameForObject(block)); if (!mappings.containsKey(name)) { mappings.put(name, (short) blockId); final IBlockState blockState = schematic.getBlockState(tePos); final Block block = blockState.getBlock(); Reference.logger.error("Block {}[{}] with TileEntity {} failed to save! Replacing with bedrock...", block, block != null ? Block.REGISTRY.getNameForObject(block) : "?", tileEntity.getClass().getName(), e); localBlocks[index] = (byte) Block.REGISTRY.getIDForObject(Blocks.BEDROCK); localMetadata[index] = 0; extraBlocks[index] = 0;
public Potion(LootCondition[] conditionsIn, @Nonnull String name, boolean splash) { super(conditionsIn); this.name = new ResourceLocation(name); this.splash = splash; if (!PotionType.REGISTRY.containsKey(this.name)) { throw new RuntimeException(name + " is not a valid potion type"); } }
protected void writeStructureToNBT(NBTTagCompound tagCompound) { super.writeStructureToNBT(tagCompound); tagCompound.setInteger("CA", Block.REGISTRY.getIDForObject(this.cropTypeA)); tagCompound.setInteger("CB", Block.REGISTRY.getIDForObject(this.cropTypeB)); tagCompound.setInteger("CC", Block.REGISTRY.getIDForObject(this.cropTypeC)); tagCompound.setInteger("CD", Block.REGISTRY.getIDForObject(this.cropTypeD)); }
public static synchronized void clearCache() { fluidFilterState.clear(); for ( final Iterator<Block> it = Block.REGISTRY.iterator(); it.hasNext(); ) { final Block block = it.next(); final int blockId = Block.REGISTRY.getIDForObject( block ); if ( BlockBitInfo.getFluidFromBlock( block ) != null ) { fluidFilterState.set( blockId ); } } if ( FMLCommonHandler.instance().getSide() == Side.CLIENT ) { updateCacheClient(); ModUtil.cacheFastStates(); } }
@SuppressWarnings({ "rawtypes" }) public static BlockStateInfo fromString(final String input) throws LocalizedException { final int start = input.indexOf('['); final int end = input.indexOf(']'); final String blockName; final String stateData; if (start > -1 && end > -1) { blockName = input.substring(0, start); stateData = input.substring(start + 1, end); } else { blockName = input; stateData = ""; } final ResourceLocation location = new ResourceLocation(blockName); if (!Block.REGISTRY.containsKey(location)) { throw new LocalizedException(Names.Messages.INVALID_BLOCK, blockName); } final Block block = Block.REGISTRY.getObject(location); final Map<IProperty, Comparable> propertyData = parsePropertyData(block.getDefaultState(), stateData, true); return new BlockStateInfo(block, propertyData); }
@Override public void postInit(FMLPostInitializationEvent event) { for(ResourceLocation r : Block.REGISTRY.getKeys()) { Block block = Block.REGISTRY.getObject(r); Item item = Item.getItemFromBlock(block); if(block == null || item == null || !(item instanceof ItemBlock) || blacklist.contains(r.toString())) continue; if(!BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.containsKey(item)) BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(item, new BehaviourBlock((ItemBlock) item, block)); } }
public MessageDownloadChunk(final ISchematic schematic, final int baseX, final int baseY, final int baseZ) { this.baseX = baseX; this.baseY = baseY; this.baseZ = baseZ; this.blocks = new short[Constants.SchematicChunk.WIDTH][Constants.SchematicChunk.HEIGHT][Constants.SchematicChunk.LENGTH]; this.metadata = new byte[Constants.SchematicChunk.WIDTH][Constants.SchematicChunk.HEIGHT][Constants.SchematicChunk.LENGTH]; this.tileEntities = new ArrayList<TileEntity>(); this.entities = new ArrayList<Entity>(); final MBlockPos pos = new MBlockPos(); for (int x = 0; x < Constants.SchematicChunk.WIDTH; x++) { for (int y = 0; y < Constants.SchematicChunk.HEIGHT; y++) { for (int z = 0; z < Constants.SchematicChunk.LENGTH; z++) { pos.set(baseX + x, baseY + y, baseZ + z); final IBlockState blockState = schematic.getBlockState(pos); final Block block = blockState.getBlock(); final int id = Block.REGISTRY.getIDForObject(block); this.blocks[x][y][z] = (short) id; this.metadata[x][y][z] = (byte) block.getMetaFromState(blockState); final TileEntity tileEntity = schematic.getTileEntity(pos); if (tileEntity != null) { this.tileEntities.add(tileEntity); } } } } }
public static IWikiProvider getWikiFor(Block block) { ResourceLocation mod = Block.REGISTRY.getNameForObject(block); return getWikiFor(mod == null ? "" : mod.getNamespace().toLowerCase()); }
private static void populateExtraAirBlocks() { extraAirBlockList.clear(); for (final String name : extraAirBlocks) { final Block block = Block.REGISTRY.getObject(new ResourceLocation(name)); if (block != Blocks.AIR) { extraAirBlockList.add(block); } } }
@Override public IBlockState build() { if(!Block.REGISTRY.containsKey(this.rLoc)) throw new IllegalArgumentException("No block found for resource location "+this.rLoc); final Block block = Block.REGISTRY.getObject(this.rLoc); final BlockStateContainer container = block.getBlockState(); IBlockState state = block.getDefaultState(); final Iterator<Entry<String, String>> it = this.properties.entrySet().iterator(); while(it.hasNext()){ final Entry<String, String> entry = it.next(); final IProperty<?> prop = container.getProperty(entry.getKey()); if(prop == null){ LogHelper.error("No property "+entry.getKey()+" found for block "+this.rLoc+". Skipping it."); it.remove(); continue; } if(!prop.parseValue(entry.getValue()).isPresent()){ LogHelper.error("Value "+entry.getValue()+" is not valid for property "+entry.getKey()+". Skipping it."); continue; } state = this.withProperty(state, prop, entry.getValue()); } return state; }
@Override public List<String> getTabCompletions(final MinecraftServer server, final ICommandSender sender, final String[] args, @Nullable final BlockPos pos) { if (args.length < 3) { return getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys()); } return Collections.emptyList(); }
@Override public boolean setBlockState(final BlockPos pos, final IBlockState blockState) { if (!isValid(pos)) { return false; } final Block block = blockState.getBlock(); final int id = Block.REGISTRY.getIDForObject(block); if (id == -1) { return false; } final int meta = block.getMetaFromState(blockState); final int x = pos.getX(); final int y = pos.getY(); final int z = pos.getZ(); this.blocks[x][y][z] = (short) id; this.metadata[x][y][z] = (byte) meta; return true; }
private static boolean isCheatyBlock(World world, BlockPos pos) { Block block = world.getBlockState(pos).getBlock(); return CHEATY_BLOCKS.contains(Block.REGISTRY.getNameForObject(block)); }
public Block getBlock(String blockName) { return Block.REGISTRY.getObject(new ResourceLocation(modID, blockName)); } }