mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 20:22:33 +00:00
Start refactoring blockstate provider
Datagenerate alt grass block models Datagenerate mystical and shiny flower models Make buried petals not extend BlockModFlower Datagenerate double flower models
This commit is contained in:
1 parent
bae7158ebb
commit
ef51fd2ff6
295 files changed
+745
-679
No files matched your search
@@ -8,38 +8,33 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.decor;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import vazkii.botania.client.fx.SparkleParticleData;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockBuriedPetals extends BlockModFlower {
|
||||
public class BlockBuriedPetals extends BushBlock implements IGrowable {
|
||||
|
||||
private static final VoxelShape SHAPE = makeCuboidShape(0, 0, 0, 16, 1.6, 16);
|
||||
|
||||
public BlockBuriedPetals(DyeColor color, Properties builder) {
|
||||
super(color, builder);
|
||||
}
|
||||
private final DyeColor color;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public Block.OffsetType getOffsetType() {
|
||||
return Block.OffsetType.NONE;
|
||||
public BlockBuriedPetals(DyeColor color, Properties builder) {
|
||||
super(builder);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -66,4 +61,21 @@ public class BlockBuriedPetals extends BlockModFlower {
|
||||
return BlockRenderType.INVISIBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(@Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, boolean fuckifiknow) {
|
||||
return world.getBlockState(pos.up()).isAir(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseBonemeal(@Nonnull World world, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull BlockState state) {
|
||||
return canGrow(world, pos, state, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(@Nonnull ServerWorld world, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull BlockState state) {
|
||||
Block block = ModBlocks.getDoubleFlower(color);
|
||||
if (block instanceof DoublePlantBlock) {
|
||||
((DoublePlantBlock) block).placeAt(world, pos, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,18 +25,19 @@ import net.minecraftforge.client.model.generators.ExistingFileHelper;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder;
|
||||
|
||||
import vazkii.botania.common.block.BlockAltGrass;
|
||||
import vazkii.botania.common.block.BlockSpecialFlower;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.*;
|
||||
import vazkii.botania.common.block.decor.BlockModMushroom;
|
||||
import vazkii.botania.common.block.decor.BlockPetalBlock;
|
||||
import vazkii.botania.common.block.decor.BlockShinyFlower;
|
||||
import vazkii.botania.common.block.string.BlockRedString;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
@@ -54,19 +55,68 @@ public class BlockstateProvider extends BlockStateProvider {
|
||||
|
||||
@Override
|
||||
protected void registerStatesAndModels() {
|
||||
Registry.BLOCK.stream().filter(b -> LibMisc.MOD_ID.equals(Registry.BLOCK.getKey(b).getNamespace()))
|
||||
.forEach(b -> {
|
||||
if (b == ModBlocks.craftCrate || b == ModBlocks.ghostRail
|
||||
|| b == ModBlocks.solidVines) {
|
||||
return;
|
||||
}
|
||||
Set<Block> blocks = Registry.BLOCK.stream()
|
||||
.filter(b -> LibMisc.MOD_ID.equals(Registry.BLOCK.getKey(b).getNamespace()))
|
||||
.collect(Collectors.toSet());
|
||||
// Manually written blockstates + models
|
||||
blocks.remove(ModBlocks.craftCrate);
|
||||
blocks.remove(ModBlocks.ghostRail);
|
||||
blocks.remove(ModBlocks.solidVines);
|
||||
|
||||
// Single blocks
|
||||
String elfGlassName = Registry.BLOCK.getKey(ModBlocks.elfGlass).getPath();
|
||||
ConfiguredModel[] elfGlassFiles = IntStream.rangeClosed(0, 3)
|
||||
.mapToObj(i -> models().getExistingFile(prefix("block/" + elfGlassName + "_" + i)))
|
||||
.map(ConfiguredModel::new).toArray(ConfiguredModel[]::new);
|
||||
getVariantBuilder(ModBlocks.elfGlass).partialState().setModels(elfGlassFiles);
|
||||
blocks.remove(ModBlocks.elfGlass);
|
||||
|
||||
String plateName = Registry.BLOCK.getKey(ModBlocks.incensePlate).getPath();
|
||||
ModelFile plateFile = models().getExistingFile(prefix("block/" + plateName));
|
||||
horizontalBlock(ModBlocks.incensePlate, plateFile, 0);
|
||||
blocks.remove(ModBlocks.incensePlate);
|
||||
|
||||
// Block types
|
||||
Predicate<Block> flowers = b -> b instanceof BlockSpecialFlower
|
||||
|| b instanceof BlockModMushroom
|
||||
|| b instanceof BlockModFlower;
|
||||
takeAll(blocks, flowers).forEach(b -> {
|
||||
String name = Registry.BLOCK.getKey(b).getPath();
|
||||
ModelFile model = models().withExistingParent(name, prefix("block/shapes/cross"))
|
||||
.texture("cross", prefix("block/" + name));
|
||||
simpleBlock(b, model);
|
||||
});
|
||||
|
||||
takeAll(blocks, ModBlocks.gaiaHead, ModBlocks.gaiaHeadWall).forEach(b -> {
|
||||
ModelFile file = models().getExistingFile(new ResourceLocation("block/soul_sand"));
|
||||
getVariantBuilder(b).partialState().setModels(new ConfiguredModel(file));
|
||||
});
|
||||
|
||||
takeAll(blocks, b -> b instanceof BlockAltGrass).forEach(b -> {
|
||||
String name = Registry.BLOCK.getKey(b).getPath();
|
||||
ResourceLocation side = prefix("block/" + name + "_side");
|
||||
ResourceLocation top = prefix("block/" + name + "_top");
|
||||
ModelFile model = models().cubeBottomTop(name, side, new ResourceLocation("block/dirt"), top);
|
||||
getVariantBuilder(b).partialState().setModels(new ConfiguredModel(model),
|
||||
new ConfiguredModel(model, 0, 90, false),
|
||||
new ConfiguredModel(model, 0, 180, false),
|
||||
new ConfiguredModel(model, 0, 270, false));
|
||||
});
|
||||
|
||||
takeAll(blocks, b -> b instanceof BlockRedString).forEach(this::redStringBlock);
|
||||
|
||||
takeAll(blocks, b -> b instanceof BlockModDoubleFlower).forEach(b -> {
|
||||
String name = Registry.BLOCK.getKey(b).getPath();
|
||||
ModelFile bottom = models().cross(name, prefix("block/" + name));
|
||||
ModelFile top = models().cross(name + "_top", prefix("block/" + name + "_top"));
|
||||
getVariantBuilder(b)
|
||||
.partialState().with(TallFlowerBlock.HALF, DoubleBlockHalf.LOWER).setModels(new ConfiguredModel(bottom))
|
||||
.partialState().with(TallFlowerBlock.HALF, DoubleBlockHalf.UPPER).setModels(new ConfiguredModel(top));
|
||||
});
|
||||
|
||||
blocks.forEach(b -> {
|
||||
String name = Registry.BLOCK.getKey(b).getPath();
|
||||
if (b instanceof BlockSpecialFlower || b instanceof BlockModMushroom) {
|
||||
ModelFile model = models().withExistingParent(name, prefix("block/shapes/cross"))
|
||||
.texture("cross", prefix("block/" + name));
|
||||
simpleBlock(b, model);
|
||||
} else if (name.contains("quartz") && b instanceof RotatedPillarBlock) {
|
||||
if (name.contains("quartz") && b instanceof RotatedPillarBlock) {
|
||||
ModelFile file = models().getExistingFile(prefix("block/" + name));
|
||||
getVariantBuilder(b)
|
||||
.partialState().with(RotatedPillarBlock.AXIS, Direction.Axis.X).setModels(new ConfiguredModel(file, 90, 90, false))
|
||||
@@ -106,31 +156,9 @@ public class BlockstateProvider extends BlockStateProvider {
|
||||
ModelFile noSide = models().getExistingFile(prefix("block/" + name + "_noside"));
|
||||
ModelFile noSideAlt = models().getExistingFile(prefix("block/" + name + "_noside_alt"));
|
||||
paneBlock((PaneBlock) b, post, side, sideAlt, noSide, noSideAlt);
|
||||
} else if (b instanceof TallFlowerBlock) {
|
||||
ModelFile bottom = models().getExistingFile(prefix("block/" + name));
|
||||
ModelFile top = models().getExistingFile(prefix("block/" + name + "_top"));
|
||||
getVariantBuilder(b)
|
||||
.partialState().with(TallFlowerBlock.HALF, DoubleBlockHalf.LOWER).setModels(new ConfiguredModel(bottom))
|
||||
.partialState().with(TallFlowerBlock.HALF, DoubleBlockHalf.UPPER).setModels(new ConfiguredModel(top));
|
||||
} else if (b instanceof BlockAltGrass) {
|
||||
ModelFile model = models().getExistingFile(prefix("block/" + name));
|
||||
getVariantBuilder(b).partialState().setModels(new ConfiguredModel(model),
|
||||
new ConfiguredModel(model, 0, 90, false),
|
||||
new ConfiguredModel(model, 0, 180, false),
|
||||
new ConfiguredModel(model, 0, 270, false));
|
||||
} else if (b == ModBlocks.gaiaHead || b == ModBlocks.gaiaHeadWall) {
|
||||
ModelFile file = models().getExistingFile(new ResourceLocation("block/soul_sand"));
|
||||
getVariantBuilder(b).partialState().setModels(new ConfiguredModel(file));
|
||||
} else if (b instanceof BlockPetalBlock) {
|
||||
ModelFile file = models().getExistingFile(prefix("block/petal_block"));
|
||||
getVariantBuilder(b).partialState().setModels(new ConfiguredModel(file));
|
||||
} else if (b instanceof BlockRedString) {
|
||||
redStringBlock(b);
|
||||
} else if (b == ModBlocks.elfGlass) {
|
||||
ConfiguredModel[] files = IntStream.rangeClosed(0, 3)
|
||||
.mapToObj(i -> models().getExistingFile(prefix("block/" + name + "_" + i)))
|
||||
.map(ConfiguredModel::new).toArray(ConfiguredModel[]::new);
|
||||
getVariantBuilder(b).partialState().setModels(files);
|
||||
} else if (b == ModBlocks.enderEye || b == ModBlocks.manaDetector) {
|
||||
ModelFile offFile = models().getExistingFile(prefix("block/" + name));
|
||||
ModelFile onFile = models().getExistingFile(prefix("block/" + name + "_powered"));
|
||||
@@ -139,15 +167,34 @@ public class BlockstateProvider extends BlockStateProvider {
|
||||
} else if (b == ModBlocks.tinyPotato || b == ModBlocks.felPumpkin || b == ModBlocks.pump) {
|
||||
ModelFile file = models().getExistingFile(prefix("block/" + name));
|
||||
horizontalBlock(b, file);
|
||||
} else if (b == ModBlocks.incensePlate) {
|
||||
ModelFile file = models().getExistingFile(prefix("block/" + name));
|
||||
horizontalBlock(b, file, 0);
|
||||
} else {
|
||||
simpleBlock(b, models().getExistingFile(prefix("block/" + name)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static <T> Iterable<T> takeAll(Set<T> src, T... items) {
|
||||
List<T> ret = Arrays.asList(items);
|
||||
src.removeAll(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static <T> Iterable<T> takeAll(Set<T> src, Predicate<T> pred) {
|
||||
List<T> ret = new ArrayList<>();
|
||||
|
||||
Iterator<T> iter = src.iterator();
|
||||
while (iter.hasNext()) {
|
||||
T item = iter.next();
|
||||
if (pred.test(item)) {
|
||||
iter.remove();
|
||||
ret.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static final Map<Direction, EnumProperty<WallHeight>> DIRECTION_TO_WALL_SIDE = ImmutableMap.<Direction, EnumProperty<WallHeight>>builder()
|
||||
.put(Direction.NORTH, WallBlock.field_235613_c_)
|
||||
.put(Direction.EAST, WallBlock.field_235612_b_)
|
||||
|
||||
@@ -30,8 +30,8 @@ public class DataGenerators {
|
||||
evt.getGenerator().addProvider(new RuneProvider(evt.getGenerator()));
|
||||
}
|
||||
if (evt.includeClient()) {
|
||||
evt.getGenerator().addProvider(new FloatingFlowerModelProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new BlockstateProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new FloatingFlowerModelProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new ItemModelProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,12 @@ import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.client.model.generators.ExistingFileHelper;
|
||||
|
||||
import vazkii.botania.common.block.BlockModDoubleFlower;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
import vazkii.botania.common.block.BlockSpecialFlower;
|
||||
import vazkii.botania.common.block.decor.BlockFloatingFlower;
|
||||
import vazkii.botania.common.block.decor.BlockModMushroom;
|
||||
import vazkii.botania.common.block.decor.BlockShinyFlower;
|
||||
import vazkii.botania.common.block.string.BlockRedString;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
@@ -37,10 +40,14 @@ public class ItemModelProvider extends net.minecraftforge.client.model.generator
|
||||
if (i instanceof BlockItem) {
|
||||
Block b = ((BlockItem) i).getBlock();
|
||||
String name = Registry.ITEM.getKey(i).getPath();
|
||||
if (b instanceof BlockSpecialFlower || b instanceof BlockModMushroom) {
|
||||
if (b instanceof BlockSpecialFlower || b instanceof BlockModMushroom
|
||||
|| b instanceof BlockModFlower
|
||||
) {
|
||||
withExistingParent(name, "item/generated").texture("layer0", prefix("block/" + name));
|
||||
} else if (b instanceof BlockFloatingFlower || b instanceof BlockRedString) {
|
||||
withExistingParent(name, prefix("block/" + name));
|
||||
} else if (b instanceof BlockModDoubleFlower) {
|
||||
withExistingParent(name, "item/generated").texture("layer0", prefix("block/" + name + "_top"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user