Flower pot plant overriding

This commit is contained in:
paulevsGitch 2021-07-12 07:13:23 +03:00
parent 5341daf326
commit 01238800ed
9 changed files with 59 additions and 28 deletions

View file

@ -18,6 +18,8 @@ import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
@ -58,6 +60,8 @@ import ru.betterend.interfaces.PottablePlant;
import ru.betterend.registry.EndBlocks;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -65,6 +69,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SplittableRandom;
import java.util.stream.Stream;
public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit {
private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID;
@ -243,12 +248,6 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
@Override
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ModelResourceLocation key = new ModelResourceLocation(stateId.getNamespace(), stateId.getPath(), "plant_age=0");
if (modelCache.containsKey(key)) {
return modelCache.get(key);
}
MultiPartBuilder model = MultiPartBuilder.create(stateDefinition);
model.part(new ModelResourceLocation(stateId.getNamespace(), stateId.getPath(), "inventory")).add();
Transformation offset = new Transformation(new Vector3f(0, 7.5F / 16F, 0), null, null, null);
@ -260,9 +259,10 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
final int compareID = i + 1;
ResourceLocation modelPath = Registry.BLOCK.getKey(plants[i]);
ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath() + ".json");
ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "models/block/" + modelPath.getPath() + "_potted.json");
if (Minecraft.getInstance().getResourceManager().hasResource(objSource)) {
objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath());
objSource = new ResourceLocation(modelPath.getNamespace(), "block/" + modelPath.getPath() + "_potted");
model.part(objSource).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add();
continue;
}
@ -335,7 +335,7 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
}
UnbakedModel result = model.build();
modelCache.put(key, result);
modelCache.put(stateId, result);
return result;
}

View file

@ -36,14 +36,14 @@ public class StoneMaterial {
public final Block slab;
public final Block wall;
public final Block button;
public final Block pressure_plate;
public final Block pressurePlate;
public final Block pedestal;
public final Block lantern;
public final Block bricks;
public final Block brick_stairs;
public final Block brick_slab;
public final Block brick_wall;
public final Block brickStairs;
public final Block brickSlab;
public final Block brickWall;
public final Block furnace;
public final Block flowerPot;
@ -58,14 +58,14 @@ public class StoneMaterial {
slab = EndBlocks.registerBlock(name + "_slab", new BaseSlabBlock(stone));
wall = EndBlocks.registerBlock(name + "_wall", new BaseWallBlock(stone));
button = EndBlocks.registerBlock(name + "_button", new BaseStoneButtonBlock(stone));
pressure_plate = EndBlocks.registerBlock(name + "_plate", new StonePressurePlateBlock(stone));
pressurePlate = EndBlocks.registerBlock(name + "_plate", new StonePressurePlateBlock(stone));
pedestal = EndBlocks.registerBlock(name + "_pedestal", new EndPedestal(stone));
lantern = EndBlocks.registerBlock(name + "_lantern", new StoneLanternBlock(stone));
bricks = EndBlocks.registerBlock(name + "_bricks", new BaseBlock(material));
brick_stairs = EndBlocks.registerBlock(name + "_bricks_stairs", new BaseStairsBlock(bricks));
brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new BaseSlabBlock(bricks));
brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks));
brickStairs = EndBlocks.registerBlock(name + "_bricks_stairs", new BaseStairsBlock(bricks));
brickSlab = EndBlocks.registerBlock(name + "_bricks_slab", new BaseSlabBlock(bricks));
brickWall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks));
furnace = EndBlocks.registerBlock(name + "_furnace", new BaseFurnaceBlock(bricks));
flowerPot = EndBlocks.registerBlock(name + "_flower_pot", new FlowerPotBlock(bricks));
@ -77,21 +77,22 @@ public class StoneMaterial {
GridRecipe.make(BetterEnd.MOD_ID, name + "_stairs", stairs).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', stone).setGroup("end_stone_stairs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_slab", slab).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###").addMaterial('#', stone).setGroup("end_stone_slabs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_stairs", brick_stairs).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', bricks).setGroup("end_stone_stairs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_slab", brick_slab).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###").addMaterial('#', bricks).setGroup("end_stone_slabs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_stairs", brickStairs).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', bricks).setGroup("end_stone_stairs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_slab", brickSlab).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###").addMaterial('#', bricks).setGroup("end_stone_slabs").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_wall", wall).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###", "###").addMaterial('#', stone).setGroup("end_wall").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_wall", brick_wall).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###", "###").addMaterial('#', bricks).setGroup("end_wall").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks_wall", brickWall).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###", "###").addMaterial('#', bricks).setGroup("end_wall").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_button", button).checkConfig(Configs.RECIPE_CONFIG).setList("#").addMaterial('#', stone).setGroup("end_stone_buttons").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_pressure_plate", pressure_plate).checkConfig(Configs.RECIPE_CONFIG).setShape("##").addMaterial('#', stone).setGroup("end_stone_plates").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_lantern", lantern).checkConfig(Configs.RECIPE_CONFIG).setShape("S", "#", "S").addMaterial('#', EndItems.CRYSTAL_SHARDS).addMaterial('S', slab, brick_slab).setGroup("end_stone_lanterns").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_pressure_plate", pressurePlate).checkConfig(Configs.RECIPE_CONFIG).setShape("##").addMaterial('#', stone).setGroup("end_stone_plates").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_lantern", lantern).checkConfig(Configs.RECIPE_CONFIG).setShape("S", "#", "S").addMaterial('#', EndItems.CRYSTAL_SHARDS).addMaterial('S', slab, brickSlab).setGroup("end_stone_lanterns").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_furnace", furnace).checkConfig(Configs.RECIPE_CONFIG).setShape("###", "# #", "###").addMaterial('#', stone).setGroup("end_stone_furnaces").build();
GridRecipe.make(BetterEnd.MOD_ID, name + "_flower_pot", flowerPot).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("# #", " # ").addMaterial('#', bricks).setGroup("end_pots").build();
CraftingRecipes.registerPedestal(name + "_pedestal", pedestal, slab, pillar);
// Item Tags //
TagHelper.addTag(ItemTags.SLABS, slab, brick_slab);
TagHelper.addTag(ItemTags.SLABS, slab, brickSlab);
TagHelper.addTag(ItemTags.STONE_BRICKS, bricks);
TagHelper.addTag(ItemTags.STONE_CRAFTING_MATERIALS, stone);
TagHelper.addTag(ItemTags.STONE_TOOL_MATERIALS, stone);
@ -99,9 +100,9 @@ public class StoneMaterial {
// Block Tags //
TagHelper.addTag(BlockTags.STONE_BRICKS, bricks);
TagHelper.addTag(BlockTags.WALLS, wall, brick_wall);
TagHelper.addTag(BlockTags.SLABS, slab, brick_slab);
TagHelper.addTags(pressure_plate, BlockTags.PRESSURE_PLATES, BlockTags.STONE_PRESSURE_PLATES);
TagHelper.addTag(BlockTags.WALLS, wall, brickWall);
TagHelper.addTag(BlockTags.SLABS, slab, brickSlab);
TagHelper.addTags(pressurePlate, BlockTags.PRESSURE_PLATES, BlockTags.STONE_PRESSURE_PLATES);
TagHelper.addTag(TagAPI.END_STONES, stone);
TagHelper.addTag(TagAPI.DRAGON_IMMUNE, stone, stairs, slab, wall);

View file

@ -122,6 +122,7 @@ public class CraftingRecipes {
GridRecipe.make(BetterEnd.MOD_ID, "neon_cactus_block_stairs", EndBlocks.NEON_CACTUS_BLOCK_STAIRS).checkConfig(Configs.RECIPE_CONFIG).setShape("# ", "## ", "###").setOutputCount(4).addMaterial('#', EndBlocks.NEON_CACTUS_BLOCK).build();
GridRecipe.make(BetterEnd.MOD_ID, "sugar_from_root", Items.SUGAR).checkConfig(Configs.RECIPE_CONFIG).setList("###").addMaterial('#', EndItems.AMBER_ROOT_RAW).build();
GridRecipe.make(BetterEnd.MOD_ID, "endstone_flower_pot", EndBlocks.ENDSTONE_FLOWER_POT).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("# #", " # ").addMaterial('#', Blocks.END_STONE_BRICKS).setGroup("end_pots").build();
}
private static void registerLantern(String name, Block lantern, Block slab) {