Draw a few ovals

This commit is contained in:
quat1024 2023-06-15 03:08:20 -04:00
parent 2b949c7e76
commit a5c0c9c893
13 changed files with 229 additions and 210 deletions

View File

@ -3,43 +3,31 @@ package io.github.cottonmc.templates;
import io.github.cottonmc.templates.block.SlopeBlock;
import io.github.cottonmc.templates.block.entity.SlopeEntity;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.function.Supplier;
public class Templates implements ModInitializer {
public static final String MODID = "templates";
public static final Block SLOPE = register("slope", new SlopeBlock(), ItemGroup.DECORATIONS);
@SuppressWarnings("unchecked")
public static final BlockEntityType<SlopeEntity> SLOPE_ENTITY = register("slope", SlopeEntity::new, SLOPE);
public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new SlopeBlock());
public static final BlockEntityType<SlopeEntity> SLOPE_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE,
id("slope"),
FabricBlockEntityTypeBuilder.create(SlopeEntity::new, SLOPE).build(null)
);
@Override
public void onInitialize() {
Registry.register(Registries.ITEM, id("slope"), (Item) new BlockItem(SLOPE, new Item.Settings()));
}
public static Block register(String name, Block block, ItemGroup tab) {
Registry.register(Registry.BLOCK, new Identifier(MODID, name), block);
BlockItem item = new BlockItem(block, new Item.Settings().group(tab));
register(name, item);
return block;
}
@SuppressWarnings("rawtypes")
public static BlockEntityType register(String name, Supplier<BlockEntity> be, Block... blocks) {
return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, name), BlockEntityType.Builder.create(be, blocks).build(null));
}
public static Item register(String name, Item item) {
Registry.register(Registry.ITEM, new Identifier(MODID, name), item);
return item;
public static Identifier id(String path) {
return new Identifier(MODID, path);
}
}

View File

@ -1,13 +1,13 @@
package io.github.cottonmc.templates.block;
import io.github.cottonmc.templates.block.entity.SlopeEntity;
import io.github.cottonmc.templates.Templates;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
@ -29,7 +29,9 @@ public class SlopeBlock extends TemplateBlock {
public static final VoxelShape WEST = VoxelShapes.cuboid(0f, 0.5f, 0f, 0.5f, 1f, 1f);
public SlopeBlock() {
super(FabricBlockSettings.of(Material.WOOD));
super(TemplateBlock.configureSettings(Settings.create())
.sounds(BlockSoundGroup.WOOD)
.hardness(0.2f)); //TODO: Material.WOOD
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(LIGHT, 0).with(REDSTONE, false));
}
@ -38,20 +40,19 @@ public class SlopeBlock extends TemplateBlock {
builder.add(FACING, LIGHT, REDSTONE);
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockView blockView) {
return new SlopeEntity();
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.SLOPE_ENTITY.instantiate(pos, state);
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getDefaultState().with(FACING, ctx.getPlayerFacing());
return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing());
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext ctx) {
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
switch(dir) {
case NORTH:
@ -68,7 +69,7 @@ public class SlopeBlock extends TemplateBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext ctx) {
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
return getCollisionShape(state, view, pos, ctx);
}
}

View File

@ -3,6 +3,7 @@ package io.github.cottonmc.templates.block;
import io.github.cottonmc.templates.Templates;
import io.github.cottonmc.templates.block.entity.TemplateEntity;
import io.github.cottonmc.templates.util.StateContainer;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
@ -17,6 +18,7 @@ import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -32,44 +34,40 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
super(settings);
}
public static Settings configureSettings(Settings s) {
return s.luminance(state -> ((TemplateBlock) state.getBlock()).luminance(state));
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if(world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity)) return true;
TemplateEntity be = (TemplateEntity) world.getBlockEntity(pos);
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if(world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity be)) return ActionResult.SUCCESS;
ItemStack stack = player.getStackInHand(hand);
if(stack.getItem() instanceof BlockItem) {
Block block = ((BlockItem) stack.getItem()).getBlock();
if(block == Blocks.REDSTONE_TORCH) {
be.addRedstone();
if(!player.abilities.creativeMode) stack.decrement(1);
if(!player.isCreative()) stack.decrement(1);
}
ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hit));
BlockState placementState = block.getPlacementState(ctx);
if(Block.isShapeFullCube(placementState.getCollisionShape(world, pos)) && !(block instanceof BlockEntityProvider)) {
if(be.getRenderedState().getBlock() == Blocks.AIR) {
be.setRenderedState(placementState);
if(!player.abilities.creativeMode) stack.decrement(1);
}
if(placementState != null &&
Block.isShapeFullCube(placementState.getCollisionShape(world, pos)) &&
!(block instanceof BlockEntityProvider) &&
be.getRenderedState().getBlock() == Blocks.AIR)
{
be.setRenderedState(placementState);
if(!player.isCreative()) stack.decrement(1);
}
} else if(stack.getItem() == Items.GLOWSTONE_DUST) {
be.addGlowstone();
if(!player.abilities.creativeMode) stack.decrement(1);
if(!player.isCreative()) stack.decrement(1);
}
return true;
return ActionResult.SUCCESS;
}
@Override
public boolean isOpaque(BlockState state) {
return false;
}
@Override
public boolean isSimpleFullBlock(BlockState state, BlockView view, BlockPos pos) {
return false;
}
@Override
public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean bool) {
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if(newState.getBlock() == Templates.SLOPE) return;
BlockEntity be = world.getBlockEntity(pos);
if(be instanceof TemplateEntity) {
@ -90,7 +88,7 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
world.spawnEntity(entity);
}
}
super.onBlockRemoved(state, world, pos, newState, bool);
super.onStateReplaced(state, world, pos, newState, moved);
}
@Override
@ -103,11 +101,6 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
}
}
@Override
public int getLuminance(BlockState state) {
return state.get(LIGHT);
}
@Override
public boolean emitsRedstonePower(BlockState state) {
return state.get(REDSTONE);
@ -149,4 +142,10 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
BlockEntity be = world.getBlockEntity(pos);
if(be instanceof TemplateEntity) ((TemplateEntity) be).setRenderedState(state);
}
//TODO: pass to Block.Settings
// "Cannot reference 'TemplateBlock.luminance' before supertype constructor has been called"
public int luminance(BlockState state) {
return state.get(LIGHT);
}
}

View File

@ -1,9 +1,11 @@
package io.github.cottonmc.templates.block.entity;
import io.github.cottonmc.templates.Templates;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
public class SlopeEntity extends TemplateEntity {
public SlopeEntity() {
super(Templates.SLOPE_ENTITY, Templates.SLOPE);
public SlopeEntity(BlockPos pos, BlockState state) {
super(Templates.SLOPE_ENTITY, pos, state, Templates.SLOPE);
}
}

View File

@ -1,6 +1,5 @@
package io.github.cottonmc.templates.block.entity;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
import net.minecraft.block.Block;
@ -9,19 +8,21 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
public abstract class TemplateEntity extends BlockEntity implements BlockEntityClientSerializable, RenderAttachmentBlockEntity {
public abstract class TemplateEntity extends BlockEntity implements RenderAttachmentBlockEntity {
protected BlockState renderedState = Blocks.AIR.getDefaultState();
protected boolean glowstone = false;
protected boolean redstone = false;
private final Block baseBlock;
public TemplateEntity(BlockEntityType<?> type, Block baseBlock) {
super(type);
public TemplateEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, Block baseBlock) {
super(type, pos, state);
this.baseBlock = baseBlock;
}
@ -35,9 +36,9 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
}
@Override
public void fromTag(CompoundTag tag) {
super.fromTag(tag);
renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState"));
public void readNbt(NbtCompound tag) {
super.readNbt(tag);
renderedState = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), tag.getCompound("BlockState"));
glowstone = tag.getBoolean("Glowstone");
redstone = tag.getBoolean("Redstone");
if(world != null && world.isClient) {
@ -49,22 +50,11 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
}
@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
tag.put("BlockState", NbtHelper.fromBlockState(renderedState));
tag.putBoolean("Glowstone", glowstone);
tag.putBoolean("Redstone", redstone);
return tag;
}
@Override
public void fromClientTag(CompoundTag tag) {
fromTag(tag);
}
@Override
public CompoundTag toClientTag(CompoundTag tag) {
return toTag(tag);
}
@Override

View File

@ -3,6 +3,7 @@ package io.github.cottonmc.templates.model;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
@ -10,12 +11,16 @@ import net.minecraft.client.texture.Sprite;
public abstract class AbstractModel implements BakedModel, FabricBakedModel {
protected static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer();
static {
if(RENDERER == null) {
throw new ExceptionInInitializerError("RenderAccess.INSTANCE must be populated");
}
}
protected final Sprite modelSprite;
protected final ModelTransformation transformation;
protected AbstractModel(
Sprite sprite,
ModelTransformation transformation) {
protected AbstractModel(Sprite sprite, ModelTransformation transformation) {
this.modelSprite = sprite;
this.transformation = transformation;
}
@ -36,8 +41,14 @@ public abstract class AbstractModel implements BakedModel, FabricBakedModel {
}
@Override
public Sprite getSprite() {
return modelSprite;
public Sprite getParticleSprite() {
//TODO
return MinecraftClient.getInstance().getBakedModelManager().getMissingModel().getParticleSprite();
}
@Override
public boolean isSideLit() {
return false; //?
}
@Override

View File

@ -4,9 +4,9 @@ import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import java.util.Random;
import java.util.function.Supplier;
public interface MeshTransformer extends QuadTransform {

View File

@ -5,22 +5,18 @@ import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.World;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
/**
@ -30,13 +26,9 @@ public class SimpleModel extends AbstractModel {
protected final Mesh mesh;
protected final Supplier<MeshTransformer> transformerFactory;
protected WeakReference<List<BakedQuad>[]> quadLists = null;
protected final ItemProxy itemProxy = new ItemProxy();
//protected final ItemProxy itemProxy = new ItemProxy();
public SimpleModel(
Mesh mesh,
Supplier<MeshTransformer> transformerFactory,
Sprite sprite,
ModelTransformation transformation) {
public SimpleModel(Mesh mesh, Supplier<MeshTransformer> transformerFactory, Sprite sprite, ModelTransformation transformation) {
super(sprite, transformation);
this.mesh = mesh;
this.transformerFactory = transformerFactory;
@ -73,21 +65,22 @@ public class SimpleModel extends AbstractModel {
}
@Override
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
return itemProxy;
}
protected class ItemProxy extends ModelItemPropertyOverrideList {
public ItemProxy() {
super(null, null, null, Collections.emptyList());
}
@Override
public BakedModel apply(BakedModel bakedModel_1, ItemStack itemStack_1, World world_1, LivingEntity livingEntity_1) {
return SimpleModel.this;
}
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}
// @Override
// public ModelItemPropertyOverrideList getItemPropertyOverrides() {
// return itemProxy;
// }
//
// protected class ItemProxy extends ModelOverrideList {
// @Override
// public BakedModel apply(BakedModel bakedModel_1, ItemStack itemStack_1, World world_1, LivingEntity livingEntity_1) {
// return SimpleModel.this;
// }
// }
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
final MeshTransformer transform = transformerFactory == null ? null : transformerFactory.get().prepare(stack, randomSupplier);

View File

@ -1,15 +1,17 @@
package io.github.cottonmc.templates.model;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
@FunctionalInterface
@ -22,12 +24,12 @@ public interface SimpleUnbakedModel extends UnbakedModel {
}
@Override
default Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) {
return Collections.emptyList();
default void setParents(Function<Identifier, UnbakedModel> function) {
// nope
}
@Override
default BakedModel bake(ModelLoader loader, Function<Identifier, Sprite> spriteFunc, ModelBakeSettings settings) {
default @Nullable BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> function, ModelBakeSettings modelBakeSettings, Identifier identifier) {
return bake();
}
}

View File

@ -1,7 +1,9 @@
package io.github.cottonmc.templates.model;
import io.github.cottonmc.templates.util.SpriteSet;
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
@ -10,12 +12,14 @@ import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite;
@ -23,10 +27,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import org.apache.commons.lang3.ObjectUtils;
import java.util.Random;
import java.util.function.Supplier;
public class SlopeModel extends SimpleModel {
@ -34,18 +38,23 @@ public class SlopeModel extends SimpleModel {
private static final ThreadLocal<Transformer> TRANSFORMERS = ThreadLocal.withInitial(Transformer::new);
public SlopeModel(BlockState blockState) {
super(baseMesh(blockState), TRANSFORMERS::get, MissingSprite.getMissingSprite(), ModelHelper.MODEL_TRANSFORM_BLOCK);
super(
baseMesh(blockState),
TRANSFORMERS::get,
SpriteSet.FALLBACK,
ModelHelper.MODEL_TRANSFORM_BLOCK
);
}
private static Mesh baseMesh(BlockState state) {
final MeshBuilder builder = RENDERER.meshBuilder();
final QuadEmitter quad = builder.getEmitter();
final Direction dir = state.get(Properties.HORIZONTAL_FACING);
drawSlope(quad.spriteColor(0, -1, -1, -1, -1), dir);
drawLeftSide(quad.spriteColor(0, -1, -1, -1, -1), dir);
drawRightSide(quad.spriteColor(0, -1, -1, -1, -1), dir);
drawBack(quad.spriteColor(0, -1, -1, -1, -1), dir);
drawBottom(quad.spriteColor(0, -1, -1, -1, -1));
drawSlope(quad.color(-1, -1, -1, -1), dir);
drawLeftSide(quad.color(-1, -1, -1, -1), dir);
drawRightSide(quad.color(-1, -1, -1, -1), dir);
drawBack(quad.color(-1, -1, -1, -1), dir);
drawBottom(quad.color(-1, -1, -1, -1));
return builder.build();
}
@ -150,9 +159,14 @@ public class SlopeModel extends SimpleModel {
if(block == Blocks.AIR) {
sprites.clear();
material = finder.clear().blendMode(0, RenderLayer.CUTOUT).find();
material = finder.clear().blendMode(BlendMode.CUTOUT).find();
} else {
material = finder.clear().disableDiffuse(0, false).disableAo(0, false).blendMode(0, block.getRenderLayer()).find();
material = finder.clear()
.disableDiffuse(false)
.ambientOcclusion(TriState.FALSE)
.blendMode(BlendMode.fromRenderLayer(RenderLayers.getBlockLayer(state)))
.find();
BakedModel model = minecraft.getBlockRenderManager().getModel(template);
sprites.prepare(model, randomSupplier.get());
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
@ -181,7 +195,7 @@ public class SlopeModel extends SimpleModel {
case TAG_SLOPE:
if(sprites.hasColor(Direction.UP)) {
quad.spriteColor(0, color, color, color, color);
quad.color(color, color, color, color);
}
paintSlope(quad, dir, sprites.getSprite(Direction.UP));
break;
@ -190,7 +204,7 @@ public class SlopeModel extends SimpleModel {
case TAG_LEFT:
final Direction leftDir = this.dir.rotateYCounterclockwise();
if(sprites.hasColor(leftDir)) {
quad.spriteColor(0, color, color, color, color);
quad.color(color, color, color, color);
}
paintLeftSide(quad, dir, sprites.getSprite(leftDir));
break;
@ -199,7 +213,7 @@ public class SlopeModel extends SimpleModel {
case TAG_RIGHT: {
final Direction rightDir = this.dir.rotateYClockwise();
if(sprites.hasColor(rightDir)) {
quad.spriteColor(0, color, color, color, color);
quad.color(color, color, color, color);
}
paintRightSide(quad, dir, sprites.getSprite(rightDir));
break;
@ -207,7 +221,7 @@ public class SlopeModel extends SimpleModel {
case TAG_BACK: {
if(sprites.hasColor(dir)) {
quad.spriteColor(0, color, color, color, color);
quad.color(color, color, color, color);
}
paintBack(quad, dir, sprites.getSprite(dir));
break;
@ -215,7 +229,7 @@ public class SlopeModel extends SimpleModel {
case TAG_BOTTOM: {
if(sprites.hasColor(Direction.DOWN)) {
quad.spriteColor(0, color, color, color, color);
quad.color(color, color, color, color);
}
paintBottom(quad, sprites.getSprite(Direction.DOWN));
break;
@ -229,28 +243,28 @@ public class SlopeModel extends SimpleModel {
private static void paintSlope(MutableQuadView quad, Direction dir, Sprite sprite) {
switch(dir) {
case NORTH:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMinV());
break;
case SOUTH:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
break;
case EAST:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
break;
case WEST:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(3, 0, sprite.getMaxU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMaxV());
default:
break;
}
@ -259,28 +273,28 @@ public class SlopeModel extends SimpleModel {
private static void paintLeftSide(MutableQuadView quad, Direction dir, Sprite sprite) {
switch(dir) {
case NORTH:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
break;
case SOUTH:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(3, 0, sprite.getMaxU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMaxV());
break;
case EAST:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
break;
case WEST:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
default:
break;
}
@ -289,28 +303,28 @@ public class SlopeModel extends SimpleModel {
private static void paintRightSide(MutableQuadView quad, Direction dir, Sprite sprite) {
switch(dir) {
case NORTH:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
break;
case SOUTH:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMinV());
break;
case EAST:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMinV());
break;
case WEST:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
default:
break;
}
@ -319,38 +333,38 @@ public class SlopeModel extends SimpleModel {
private static void paintBack(MutableQuadView quad, Direction dir, Sprite sprite) {
switch(dir) {
case NORTH:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
break;
case SOUTH:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
break;
case EAST:
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
break;
case WEST:
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
default:
break;
}
}
private static void paintBottom(MutableQuadView quad, Sprite sprite) {
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
}
}
}

View File

@ -8,7 +8,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.client.render.block.BlockModels;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import java.util.HashMap;
import java.util.function.Function;
@ -28,6 +28,6 @@ public class TemplateModelVariantProvider implements ModelVariantProvider {
for(BlockState state : block.getStateManager().getStates()) {
variants.put(BlockModels.getModelId(state), (SimpleUnbakedModel) () -> model.apply(state));
}
variants.put(new ModelIdentifier(Registry.ITEM.getId(block.asItem()), "inventory"), (SimpleUnbakedModel) () -> model.apply(itemState));
variants.put(new ModelIdentifier(Registries.ITEM.getId(block.asItem()), "inventory"), (SimpleUnbakedModel) () -> model.apply(itemState));
}
}

View File

@ -7,17 +7,24 @@ import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import java.util.List;
import java.util.Random;
public class SpriteSet {
private Object2ObjectOpenHashMap<Direction, BakedQuad> quads = new Object2ObjectOpenHashMap<>();
private boolean isDefault = true;
public static final Sprite DEFAULT = MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("minecraft:block/scaffolding_top"));
public static final Sprite FALLBACK = MissingSprite.getMissingSprite();
public static final Sprite DEFAULT = findSprite(new Identifier("minecraft:block/scaffolding_top"));
public static final Sprite FALLBACK = findSprite(MissingSprite.getMissingSpriteId());
private static Sprite findSprite(Identifier id) {
Sprite s = MinecraftClient.getInstance().getBakedModelManager().getAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).getSprite(id);
if(false) throw new IllegalStateException("null sprite " + id);
else return s;
}
public SpriteSet() {
clear();
@ -43,16 +50,26 @@ public class SpriteSet {
}
public Sprite getSprite(Direction dir) {
//TODO
if(true) return MinecraftClient.getInstance().getBakedModelManager().getMissingModel().getParticleSprite();
if(isDefault) return DEFAULT;
BakedQuad quad = quads.get(dir);
if(quad == null) return FALLBACK;
return quad.getSprite();
Sprite sprite = quad.getSprite();
if(sprite == null) return FALLBACK;
return sprite;
}
public boolean hasColor(Direction dir) {
if(isDefault) return false;
BakedQuad quad = quads.get(dir);
if(quad == null) return false;
return quad.hasColor();
}
}

View File

@ -19,7 +19,9 @@
]
},
"depends": {
"fabricloader": ">=0.4.0",
"minecraft": ">=1.20.1",
"fabricloader": "*",
"fabric-api": "*",
"fabric-renderer-indigo": "*"
}
}