mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 19:49:41 +00:00
Add back tooltip support to the BlockItems and add an blank json generator for block drops.
This commit is contained in:
1 parent
8c218786d4
commit
6be0e4f310
5 files changed
+152
-7
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package slimeknights.mantle.block;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.block.Block;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
public class ExampleGeneratedJsonBlock extends Block implements IGeneratedJson {
|
||||
|
||||
public ExampleGeneratedJsonBlock(Properties p_i48440_1_) {
|
||||
super(p_i48440_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentToUse() {
|
||||
return "block/cube_all";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getTexturesToUse() {
|
||||
JsonObject textures = new JsonObject();
|
||||
|
||||
textures.addProperty("all", this.getRegistryName().getNamespace() + ":block/" + this.getRegistryName().getPath());
|
||||
|
||||
return textures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getVariants() {
|
||||
JsonObject variants = new JsonObject();
|
||||
JsonObject variant = new JsonObject();
|
||||
|
||||
variant.addProperty("model", this.getRegistryName().getNamespace() + ":block/" + this.getRegistryName().getPath());
|
||||
variants.add("", variant);
|
||||
|
||||
return variants;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import slimeknights.mantle.item.BlockTooltipItem;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -91,7 +92,7 @@ public interface IRegisterUtil {
|
||||
* @return Registered item block
|
||||
*/
|
||||
default BlockItem registerBlockItem(IForgeRegistry<Item> registry, Block block, ItemGroup group) {
|
||||
BlockItem itemBlock = new BlockItem(block, new Item.Properties().group(group));
|
||||
BlockItem itemBlock = new BlockTooltipItem(block, new Item.Properties().group(group));
|
||||
return this.register(registry, itemBlock, block.getRegistryName());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package slimeknights.mantle.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import slimeknights.mantle.util.LocUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockTooltipItem extends BlockItem {
|
||||
public BlockTooltipItem(Block blockIn, Item.Properties builder) {
|
||||
super(blockIn, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
if (I18n.hasKey(stack.getDisplayName()+ ".tooltip")) {
|
||||
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() + LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
|
||||
}
|
||||
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,7 @@ public class TooltipItem extends Item {
|
||||
|
||||
public static void addOptionalTooltip(ItemStack stack, List<ITextComponent> tooltip) {
|
||||
if (I18n.hasKey(stack.getDisplayName() + ".tooltip")) {
|
||||
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
|
||||
}
|
||||
else if (I18n.hasKey(stack.getDisplayName() + ".tooltip")) {
|
||||
tooltip.addAll(LocUtils.getTooltips(
|
||||
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
|
||||
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() + LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package slimeknights.tconstruct.library;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class BlankBlockDropJsonGenerator implements IDataProvider {
|
||||
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
|
||||
private final DataGenerator generator;
|
||||
private final String modId;
|
||||
|
||||
public BlankBlockDropJsonGenerator(DataGenerator generatorIn, String modId) {
|
||||
this.generator = generatorIn;
|
||||
this.modId = modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(DirectoryCache cache) throws IOException {
|
||||
JsonObject blockState = new JsonObject();
|
||||
int generatedEntries = 0;
|
||||
JsonObject blockstateCache = new JsonObject();
|
||||
|
||||
Path cacheP = this.generator.getOutputFolder().resolve("cache/" + this.modId + "/loot_tables/blocks/blocks.json");
|
||||
|
||||
if (Files.exists(cacheP)) {
|
||||
String jsonTxt = IOUtils.toString(cacheP.toUri(), "UTF-8");
|
||||
blockstateCache = new JsonParser().parse(jsonTxt).getAsJsonObject();
|
||||
}
|
||||
|
||||
for (Block block : Registry.BLOCK) {
|
||||
blockState = new JsonObject();
|
||||
ResourceLocation resourcelocation = Registry.BLOCK.getKey(block);
|
||||
|
||||
if (!resourcelocation.getNamespace().equals(this.modId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (blockstateCache.has(resourcelocation.toString())) {
|
||||
continue;
|
||||
}
|
||||
blockState.addProperty("REPLACEME", "TRUE");
|
||||
|
||||
blockstateCache.addProperty(resourcelocation.toString(), "UNUSED");
|
||||
generatedEntries++;
|
||||
|
||||
Path path = this.generator.getOutputFolder().resolve("assets/" + this.modId + "/loot_tables/blocks/" + resourcelocation.getPath() + ".json");
|
||||
IDataProvider.save(GSON, cache, blockState, path);
|
||||
}
|
||||
|
||||
if (generatedEntries != 0) {
|
||||
IDataProvider.save(GSON, cache, blockstateCache, cacheP);
|
||||
}
|
||||
|
||||
cache.func_218456_c(cacheP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a name for this provider, to use in logging.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Blank Block Drops Generator";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user