下面列出了怎么用net.minecraft.util.ResourceLocation的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Get resource location from url
*
* @param url - url to get the file from
* @return ResourceLocation
*/
public static ResourceLocation getTexture(URL url) {
init();
if (!URL_TEXTURES.containsKey(url)) {
URL_TEXTURES.put(url, new WrappedResource(null));
queueImage(url);
}
WrappedResource wr = URL_TEXTURES.get(url);
if (wr.location == null) {
if (URL_IMAGES.get(url) != null && URL_IMAGES.get(url).image != null) {
DynamicTexture texture = new DynamicTexture(URL_IMAGES.get(url).image);
WrappedResource wr2 = new WrappedResource(FMLClientHandler.instance().getClient().getTextureManager().getDynamicTextureLocation(url.toString(), texture));
URL_TEXTURES.put(url, wr2);
return wr2.location;
} else {
return FULLY_TRANSPARENT_TEXTURE;
}
}
return wr.location;
}
public GuiReactorRedstonePort(Container container, TileEntityReactorRedstonePort tileentity) {
super(container);
_guiBackground = new ResourceLocation(BigReactors.GUI_DIRECTORY + "RedstonePort.png");
port = tileentity;
ySize = 204;
btnMap = new HashMap<CircuitType, GuiSelectableButton>();
outputLevel = tileentity.getOutputLevel();
greaterThan = tileentity.getGreaterThan();
activeOnPulse = tileentity.isInputActiveOnPulse();
if(outputLevel < 0) {
retract = true;
outputLevel = Math.abs(outputLevel);
}
else {
retract = false;
}
}
@Nonnull
public static TextureAtlasSprite registerIcon(@Nonnull ResourceLocation texturePath) {
// Validate parameters.
Preconditions.checkNotNull(texturePath, "IconHelper cannot register an icon with a null texture path!");
// The icon to be returned.
TextureAtlasSprite ret = null;
// Attempt to register the sprite to the MineCraft texture map.
try {
ret = Minecraft.getMinecraft().getTextureMapBlocks().registerSprite(texturePath);
} catch (Exception e) {
AgriCore.getLogger("agricraft").debug(e.getLocalizedMessage());
}
// Return the icon, or the default icon in the case that the icon was null.
if (ret != null) {
return ret;
} else {
return getDefaultIcon();
}
}
@Override
public Set<ResourceLocation> getLanguageFiles() {
Pattern langPattern = Pattern.compile("^[a-zA-Z0-9-]+\\.lang$", Pattern.CASE_INSENSITIVE);
Set<ResourceLocation> langFiles = new HashSet<>();
for (String domain : getResourceDomains()) {
findFileCaseInsensitive("assets/" + domain + "/lang/").filter(File::isDirectory).ifPresent(file -> {
Arrays.stream(file.listFiles((dir, name) -> langPattern.asPredicate().test(name)))
.map(File::getName)
.forEach(name -> langFiles.add(new ResourceLocation(domain, name)));
});
}
return langFiles;
}
@Override
public void generate(World world, BlockPos pos)
{
PlacementSettings settings = new PlacementSettings();
Template temp = null;
String suffix = world.provider.getDimensionType().getSuffix();
String opts = world.getWorldInfo().getGeneratorOptions() + suffix;
if (!Strings.isNullOrEmpty(opts))
temp = StructureUtil.loadTemplate(new ResourceLocation(opts), (WorldServer)world, true);
if (temp == null)
temp = StructureUtil.loadTemplate(new ResourceLocation("/config/", this.fileName + suffix), (WorldServer)world, !Strings.isNullOrEmpty(suffix));
if (temp == null)
return; //If we're not in the overworld, and we don't have a template...
BlockPos spawn = StructureUtil.findSpawn(temp, settings);
if (spawn != null)
{
pos = pos.subtract(spawn);
world.setSpawnPoint(pos);
}
temp.addBlocksToWorld(world, pos, settings, 0); //Push to world, with no neighbor notifications!
world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
}
@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
/*
* Iterates both the stack array and resource location array to create a 2d
* table
*/
if (GTConfig.general.addLootItems) {
for (ItemStack item : lootpool) {
for (ResourceLocation table : loottable) {
if (event.getName().equals(table)) {
event.getTable().getPool("main").addEntry(new LootEntryItem(item.getItem(), 16, 0, new LootFunction[] {
createCountFunction(1, 6) }, NO_CONDITIONS, getStackResourceName(item)));
}
}
}
}
}
@Override
protected void writeEntityToNBT(NBTTagCompound compound)
{
Block block = this.blockState != null ? this.blockState.getBlock() : Blocks.AIR;
ResourceLocation rl = Block.REGISTRY.getNameForObject(block);
compound.setString("Block", rl == null ? "" : rl.toString());
compound.setByte("Data", this.blockState != null ? (byte) block.getMetaFromState(this.blockState) : 0);
compound.setInteger("Time", this.fallTime);
compound.setBoolean("DropItem", this.shouldDropItem);
compound.setBoolean("HurtEntities", this.hurtEntities);
compound.setFloat("FallHurtAmount", this.fallHurtAmount);
compound.setInteger("FallHurtMax", this.fallHurtMax);
if (this.tileEntityData != null)
{
compound.setTag("TileEntityData", this.tileEntityData);
}
}
public static List<String> getListOfStringsMatchingLastWord(String[] p_175762_0_, Collection<?> p_175762_1_) {
String s = p_175762_0_[p_175762_0_.length - 1];
List<String> list = new ArrayList<>();
if (!p_175762_1_.isEmpty()) {
list = p_175762_1_.stream().map(Functions.toStringFunction()::apply).collect(Collectors.toList()).stream().filter(s2 ->
doesStringStartWith(s, s2)).collect(Collectors.toList());
if (list.isEmpty()) {
for (Object object : p_175762_1_) {
if (object instanceof ResourceLocation && doesStringStartWith(s, ((ResourceLocation) object).getResourcePath())) {
list.add(String.valueOf(object));
}
}
}
}
return list;
}
public boolean isTargetBlockUnchanged()
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server == null)
{
return false;
}
World world = server.getWorld(this.dimension);
if (world == null)
{
return false;
}
IBlockState iBlockState = world.getBlockState(this.pos);
Block block = iBlockState.getBlock();
ResourceLocation rl = ForgeRegistries.BLOCKS.getKey(block);
int meta = block.getMetaFromState(iBlockState);
// The target block unique name and metadata matches what we have stored
return this.blockMeta == meta && rl != null && this.blockName.equals(rl.toString());
}
public ItemPLRecord(String name, SoundEvent soundEvent) {
super(name, soundEvent);
this.name = name;
this.setCreativeTab(ProductionLine.creativeTabPL);
this.setUnlocalizedName(MOD_ID + "." + name);
GameRegistry.<Item>register(this, new ResourceLocation(MOD_ID, name));
}
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Vec3d position = spell.getTarget(world);
if (position == null) return;
ParticleBuilder glitter = new ParticleBuilder(1);
glitter.setAlphaFunction(new InterpFloatInOut(0.0f, 0.1f));
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter.enableMotionCalculation();
glitter.setScaleFunction(new InterpScale(1, 0));
glitter.setAcceleration(new Vec3d(0, -0.02, 0));
glitter.setCollision(true);
glitter.setCanBounce(true);
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(position), RandUtil.nextInt(5, 15), 0, (aFloat, particleBuilder) -> {
double radius = 2;
double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
double r = radius * RandUtil.nextFloat();
double x = r * MathHelper.cos((float) theta);
double z = r * MathHelper.sin((float) theta);
glitter.setScale(RandUtil.nextFloat());
glitter.setPositionOffset(new Vec3d(x, RandUtil.nextDouble(-2, 2), z));
glitter.setLifetime(RandUtil.nextInt(50, 100));
Vec3d direction = position.add(glitter.getPositionOffset()).subtract(position).normalize().scale(1 / 5);
glitter.addMotion(direction.scale(RandUtil.nextDouble(0.5, 1)));
});
}
private static void registerItemModelWithNamePrefix(ItemEnderUtilities item, int meta, String namePrefix)
{
if (item.isEnabled())
{
ResourceLocation rl = item.getRegistryName();
ModelLoader.setCustomModelResourceLocation(item, meta,
new ModelResourceLocation(rl.getNamespace() + ":" + namePrefix + rl.getPath(), "inventory"));
}
}
public MetaTileEntityItemCollector(ResourceLocation metaTileEntityId, int tier, int maxItemSuckingRange) {
super(metaTileEntityId, tier);
this.maxItemSuckingRange = maxItemSuckingRange;
this.itemSuckingRange = maxItemSuckingRange;
this.itemFilter = new ItemFilterContainer(this::markDirty);
initializeInventory();
}
@Override
protected ResourceLocation getEntityTexture(EntityTiger entity)
{
if(entity.getTigerType() == TigerType.Snow)
return texTigerSnow;
return texTiger;
}
private TemplateEnderUtilities getTemplate(World world, EntityPlayer player, ItemStack stack, PlacementSettings placement)
{
TemplateManagerEU templateManager = this.getTemplateManager();
ResourceLocation rl = this.getTemplateResource(stack, player);
TemplateEnderUtilities template = templateManager.getTemplate(rl);
template.setPlacementSettings(placement);
return template;
}
public ResearchItem(String key, String category, AspectList tags, int col, int row, int complex, ResourceLocation icon)
{
this.key = key;
this.category = category;
this.tags = tags;
this.icon_resource = icon;
this.icon_item = null;
this.displayColumn = col;
this.displayRow = row;
this.complexity = complex;
if (complexity < 1) this.complexity = 1;
if (complexity > 3) this.complexity = 3;
}
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Vec3d position = spell.getTarget(world);
if (position == null) return;
ParticleBuilder glitter = new ParticleBuilder(0);
if (RandUtil.nextInt(5) != 0)
glitter.setColor(instance.getPrimaryColor());
else glitter.setColor(instance.getSecondaryColor());
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SMOKE));
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(position), 20, 0, (aFloat, particleBuilder) -> {
particleBuilder.setLifetime(RandUtil.nextInt(10, 40));
particleBuilder.setScale(RandUtil.nextFloat(5, 10));
particleBuilder.setAlpha(RandUtil.nextFloat(0.3f, 0.5f));
particleBuilder.setAlphaFunction(new InterpFloatInOut(0.3f, 0.4f));
double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);
double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
double r = area * RandUtil.nextFloat();
double x = r * MathHelper.cos((float) theta);
double z = r * MathHelper.sin((float) theta);
particleBuilder.setPositionOffset(new Vec3d(x, RandUtil.nextDouble(-r, r), z));
particleBuilder.setMotion(new Vec3d(RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01)));
// particleBuilder.setAcceleration(new Vec3d(0, -0.015, 0));
});
}
public static <T extends Item> T registerItem(IForgeRegistry<Item> reg, T item, String name) {
item.setRegistryName(new ResourceLocation(CommunityGlobals.MOD_ID, name));
item.setTranslationKey(CommunityGlobals.MOD_ID + '.' + name);
item.setCreativeTab(CommunityGlobals.TAB);
reg.register(item);
return item;
}
@Override
public SoundEvent getBreakSound() {
return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK)
.map(sound -> (sound.domain.isEmpty() && !sound.name.contains(".")) ? "dig." + sound.name : sound.getID())
.map(soundID -> SoundEvent.REGISTRY.getObject(new ResourceLocation(soundID)))
.orElseGet(super::getBreakSound);
}
private static IModel getModel(Optional<ResourceLocation> model) {
if (model.isPresent()) {
ResourceLocation location = model.get();
return ModelLoaderRegistry.getModelOrLogError(location, "Couldn't load base-model dependency: " + location);
} else {
return ModelLoaderRegistry.getMissingModel();
}
}
public Info(int width, List<String> lines, ResourceLocation logoPath, Dimension logoDims)
{
super(GuiCustomizeWorld.this.mc,
width,
GuiCustomizeWorld.this.height,
32, GuiCustomizeWorld.this.height - 68 + 4,
LIST_WIDTH + 20, 60,
GuiCustomizeWorld.this.width,
GuiCustomizeWorld.this.height);
this.lines = resizeContent(lines);
this.logoPath = logoPath;
this.logoDims = logoDims;
this.setHeaderInfo(true, getHeaderHeight());
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(EntityTofuCow entity) {
if(entity.getVariant() == 1){
return ZUNDACOW_TEXTURES;
}else {
return COW_TEXTURES;
}
}
public BlockTraverseSapling(String name, TraverseTreeGenerator generator) {
super();
this.generator = generator;
setRegistryName(new ResourceLocation(TraverseConstants.MOD_ID, name + "_sapling"));
setTranslationKey(getRegistryName().toString());
setCreativeTab(TraverseTab.TAB);
setSoundType(SoundType.PLANT);
ShootingStar.registerModel(new ModelCompound(TraverseConstants.MOD_ID, this, "sapling", STAGE, TYPE));
}
public static ResourceLocation getParticleTexture()
{
try
{
return (ResourceLocation)ReflectionHelper.getPrivateValue(EffectRenderer.class, null, new String[] { "particleTextures", "b", "field_110737_b" }); } catch (Exception e) {
}
return null;
}
@Override
public Collection<ResourceLocation> getTextures()
{
List<ResourceLocation> textures = Lists.newArrayList();
for (String name : this.getTextureMapping().values())
{
textures.add(new ResourceLocation(name));
}
return textures;
}
public static Colour[] loadTextureColours(ResourceLocation resource) {
int[] idata = loadTextureData(resource);
Colour[] data = new Colour[idata.length];
for (int i = 0; i < data.length; i++)
data[i] = new ColourARGB(idata[i]);
return data;
}
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceShape instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
IShapeOverrides overrides = spellRing.getOverrideHandler().getConsumerInterface(IShapeOverrides.class);
if (overrides.onRenderTouch(world, spell, spellRing)) return;
Entity targetEntity = spell.getVictim(world);
if (targetEntity == null) return;
ParticleBuilder glitter = new ParticleBuilder(1);
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
ParticleSpawner.spawn(glitter, world, new InterpCircle(targetEntity.getPositionVector().add(0, targetEntity.height / 2.0, 0), new Vec3d(0, 1, 0), 1, 10), 50, RandUtil.nextInt(10, 15), (aFloat, particleBuilder) -> {
if (RandUtil.nextBoolean()) {
glitter.setColor(spellRing.getPrimaryColor());
glitter.setMotion(new Vec3d(0, RandUtil.nextDouble(0.01, 0.1), 0));
} else {
glitter.setColor(spellRing.getSecondaryColor());
glitter.setMotion(new Vec3d(0, RandUtil.nextDouble(-0.1, -0.01), 0));
}
glitter.setLifetime(RandUtil.nextInt(20, 30));
glitter.setScale((float) RandUtil.nextDouble(0.3, 1));
glitter.setAlphaFunction(new InterpFloatInOut(0.3f, (float) RandUtil.nextDouble(0.6, 1)));
glitter.setLifetime(RandUtil.nextInt(10, 20));
glitter.setScaleFunction(new InterpScale(1, 0));
});
}
private ResourceLocation getTemplateResource(ItemStack stack, EntityPlayer player)
{
int id = this.getSelectionIndex(stack);
UUID uuid = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
String name = NBTUtils.getOrCreateString(stack, WRAPPER_TAG_NAME, "player", player.getName());
return new ResourceLocation(Reference.MOD_ID, name + "_" + uuid.toString() + "_" + id);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(TextureMap textureMap) {
this.sprites = new TextureAtlasSprite[6];
for (CubeSide cubeSide : CubeSide.values()) {
String fullPath = String.format("blocks/%s/%s", basePath, cubeSide.name().toLowerCase());
this.sprites[cubeSide.ordinal()] = textureMap.registerSprite(new ResourceLocation(GTValues.MODID, fullPath));
}
}
public ResearchItem(String key, String category, AspectList tags, int col, int row, int complex, ResourceLocation icon)
{
this.key = key;
this.category = category;
this.tags = tags;
this.icon_resource = icon;
this.icon_item = null;
this.displayColumn = col;
this.displayRow = row;
this.complexity = complex;
if (complexity < 1) this.complexity = 1;
if (complexity > 3) this.complexity = 3;
}