Draw a few ovals
This commit is contained in:
parent
2b949c7e76
commit
a5c0c9c893
@ -3,43 +3,31 @@ package io.github.cottonmc.templates;
|
|||||||
import io.github.cottonmc.templates.block.SlopeBlock;
|
import io.github.cottonmc.templates.block.SlopeBlock;
|
||||||
import io.github.cottonmc.templates.block.entity.SlopeEntity;
|
import io.github.cottonmc.templates.block.entity.SlopeEntity;
|
||||||
import net.fabricmc.api.ModInitializer;
|
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.Block;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
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.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class Templates implements ModInitializer {
|
public class Templates implements ModInitializer {
|
||||||
public static final String MODID = "templates";
|
public static final String MODID = "templates";
|
||||||
|
|
||||||
public static final Block SLOPE = register("slope", new SlopeBlock(), ItemGroup.DECORATIONS);
|
public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new SlopeBlock());
|
||||||
@SuppressWarnings("unchecked")
|
public static final BlockEntityType<SlopeEntity> SLOPE_ENTITY = Registry.register(
|
||||||
public static final BlockEntityType<SlopeEntity> SLOPE_ENTITY = register("slope", SlopeEntity::new, SLOPE);
|
Registries.BLOCK_ENTITY_TYPE,
|
||||||
|
id("slope"),
|
||||||
|
FabricBlockEntityTypeBuilder.create(SlopeEntity::new, SLOPE).build(null)
|
||||||
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
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) {
|
public static Identifier id(String path) {
|
||||||
Registry.register(Registry.BLOCK, new Identifier(MODID, name), block);
|
return new Identifier(MODID, path);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package io.github.cottonmc.templates.block;
|
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.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Material;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.entity.EntityContext;
|
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.DirectionProperty;
|
import net.minecraft.state.property.DirectionProperty;
|
||||||
import net.minecraft.state.property.Properties;
|
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 static final VoxelShape WEST = VoxelShapes.cuboid(0f, 0.5f, 0f, 0.5f, 1f, 1f);
|
||||||
|
|
||||||
public SlopeBlock() {
|
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));
|
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);
|
builder.add(FACING, LIGHT, REDSTONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity createBlockEntity(BlockView blockView) {
|
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||||
return new SlopeEntity();
|
return Templates.SLOPE_ENTITY.instantiate(pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
return getDefaultState().with(FACING, ctx.getPlayerFacing());
|
return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
Direction dir = state.get(FACING);
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
@ -68,7 +69,7 @@ public class SlopeBlock extends TemplateBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getCollisionShape(state, view, pos, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package io.github.cottonmc.templates.block;
|
|||||||
import io.github.cottonmc.templates.Templates;
|
import io.github.cottonmc.templates.Templates;
|
||||||
import io.github.cottonmc.templates.block.entity.TemplateEntity;
|
import io.github.cottonmc.templates.block.entity.TemplateEntity;
|
||||||
import io.github.cottonmc.templates.util.StateContainer;
|
import io.github.cottonmc.templates.util.StateContainer;
|
||||||
|
import net.minecraft.block.AbstractBlock;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@ -17,6 +18,7 @@ import net.minecraft.item.ItemUsageContext;
|
|||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
import net.minecraft.state.property.IntProperty;
|
import net.minecraft.state.property.IntProperty;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -32,44 +34,40 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
|
|||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Settings configureSettings(Settings s) {
|
||||||
|
return s.luminance(state -> ((TemplateBlock) state.getBlock()).luminance(state));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
if(world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity)) return true;
|
if(world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity be)) return ActionResult.SUCCESS;
|
||||||
TemplateEntity be = (TemplateEntity) world.getBlockEntity(pos);
|
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
if(stack.getItem() instanceof BlockItem) {
|
if(stack.getItem() instanceof BlockItem) {
|
||||||
Block block = ((BlockItem) stack.getItem()).getBlock();
|
Block block = ((BlockItem) stack.getItem()).getBlock();
|
||||||
if(block == Blocks.REDSTONE_TORCH) {
|
if(block == Blocks.REDSTONE_TORCH) {
|
||||||
be.addRedstone();
|
be.addRedstone();
|
||||||
if(!player.abilities.creativeMode) stack.decrement(1);
|
if(!player.isCreative()) stack.decrement(1);
|
||||||
}
|
}
|
||||||
ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hit));
|
ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hit));
|
||||||
BlockState placementState = block.getPlacementState(ctx);
|
BlockState placementState = block.getPlacementState(ctx);
|
||||||
if(Block.isShapeFullCube(placementState.getCollisionShape(world, pos)) && !(block instanceof BlockEntityProvider)) {
|
if(placementState != null &&
|
||||||
if(be.getRenderedState().getBlock() == Blocks.AIR) {
|
Block.isShapeFullCube(placementState.getCollisionShape(world, pos)) &&
|
||||||
be.setRenderedState(placementState);
|
!(block instanceof BlockEntityProvider) &&
|
||||||
if(!player.abilities.creativeMode) stack.decrement(1);
|
be.getRenderedState().getBlock() == Blocks.AIR)
|
||||||
}
|
{
|
||||||
|
be.setRenderedState(placementState);
|
||||||
|
if(!player.isCreative()) stack.decrement(1);
|
||||||
}
|
}
|
||||||
} else if(stack.getItem() == Items.GLOWSTONE_DUST) {
|
} else if(stack.getItem() == Items.GLOWSTONE_DUST) {
|
||||||
be.addGlowstone();
|
be.addGlowstone();
|
||||||
if(!player.abilities.creativeMode) stack.decrement(1);
|
if(!player.isCreative()) stack.decrement(1);
|
||||||
}
|
}
|
||||||
return true;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpaque(BlockState state) {
|
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
||||||
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) {
|
|
||||||
if(newState.getBlock() == Templates.SLOPE) return;
|
if(newState.getBlock() == Templates.SLOPE) return;
|
||||||
BlockEntity be = world.getBlockEntity(pos);
|
BlockEntity be = world.getBlockEntity(pos);
|
||||||
if(be instanceof TemplateEntity) {
|
if(be instanceof TemplateEntity) {
|
||||||
@ -90,7 +88,7 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
|
|||||||
world.spawnEntity(entity);
|
world.spawnEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onBlockRemoved(state, world, pos, newState, bool);
|
super.onStateReplaced(state, world, pos, newState, moved);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -103,11 +101,6 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLuminance(BlockState state) {
|
|
||||||
return state.get(LIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean emitsRedstonePower(BlockState state) {
|
public boolean emitsRedstonePower(BlockState state) {
|
||||||
return state.get(REDSTONE);
|
return state.get(REDSTONE);
|
||||||
@ -149,4 +142,10 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
|
|||||||
BlockEntity be = world.getBlockEntity(pos);
|
BlockEntity be = world.getBlockEntity(pos);
|
||||||
if(be instanceof TemplateEntity) ((TemplateEntity) be).setRenderedState(state);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package io.github.cottonmc.templates.block.entity;
|
package io.github.cottonmc.templates.block.entity;
|
||||||
|
|
||||||
import io.github.cottonmc.templates.Templates;
|
import io.github.cottonmc.templates.Templates;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class SlopeEntity extends TemplateEntity {
|
public class SlopeEntity extends TemplateEntity {
|
||||||
public SlopeEntity() {
|
public SlopeEntity(BlockPos pos, BlockState state) {
|
||||||
super(Templates.SLOPE_ENTITY, Templates.SLOPE);
|
super(Templates.SLOPE_ENTITY, pos, state, Templates.SLOPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.cottonmc.templates.block.entity;
|
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.networking.v1.PlayerLookup;
|
||||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
|
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
|
||||||
import net.minecraft.block.Block;
|
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.BlockEntity;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
import net.minecraft.nbt.NbtHelper;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
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 BlockState renderedState = Blocks.AIR.getDefaultState();
|
||||||
protected boolean glowstone = false;
|
protected boolean glowstone = false;
|
||||||
protected boolean redstone = false;
|
protected boolean redstone = false;
|
||||||
private final Block baseBlock;
|
private final Block baseBlock;
|
||||||
|
|
||||||
public TemplateEntity(BlockEntityType<?> type, Block baseBlock) {
|
public TemplateEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, Block baseBlock) {
|
||||||
super(type);
|
super(type, pos, state);
|
||||||
this.baseBlock = baseBlock;
|
this.baseBlock = baseBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,9 +36,9 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromTag(CompoundTag tag) {
|
public void readNbt(NbtCompound tag) {
|
||||||
super.fromTag(tag);
|
super.readNbt(tag);
|
||||||
renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState"));
|
renderedState = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), tag.getCompound("BlockState"));
|
||||||
glowstone = tag.getBoolean("Glowstone");
|
glowstone = tag.getBoolean("Glowstone");
|
||||||
redstone = tag.getBoolean("Redstone");
|
redstone = tag.getBoolean("Redstone");
|
||||||
if(world != null && world.isClient) {
|
if(world != null && world.isClient) {
|
||||||
@ -49,22 +50,11 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag toTag(CompoundTag tag) {
|
public void writeNbt(NbtCompound tag) {
|
||||||
super.toTag(tag);
|
super.writeNbt(tag);
|
||||||
tag.put("BlockState", NbtHelper.fromBlockState(renderedState));
|
tag.put("BlockState", NbtHelper.fromBlockState(renderedState));
|
||||||
tag.putBoolean("Glowstone", glowstone);
|
tag.putBoolean("Glowstone", glowstone);
|
||||||
tag.putBoolean("Redstone", redstone);
|
tag.putBoolean("Redstone", redstone);
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromClientTag(CompoundTag tag) {
|
|
||||||
fromTag(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundTag toClientTag(CompoundTag tag) {
|
|
||||||
return toTag(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.Renderer;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
|
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
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.BakedModel;
|
||||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
@ -10,12 +11,16 @@ import net.minecraft.client.texture.Sprite;
|
|||||||
public abstract class AbstractModel implements BakedModel, FabricBakedModel {
|
public abstract class AbstractModel implements BakedModel, FabricBakedModel {
|
||||||
protected static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer();
|
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 Sprite modelSprite;
|
||||||
protected final ModelTransformation transformation;
|
protected final ModelTransformation transformation;
|
||||||
|
|
||||||
protected AbstractModel(
|
protected AbstractModel(Sprite sprite, ModelTransformation transformation) {
|
||||||
Sprite sprite,
|
|
||||||
ModelTransformation transformation) {
|
|
||||||
this.modelSprite = sprite;
|
this.modelSprite = sprite;
|
||||||
this.transformation = transformation;
|
this.transformation = transformation;
|
||||||
}
|
}
|
||||||
@ -36,8 +41,14 @@ public abstract class AbstractModel implements BakedModel, FabricBakedModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sprite getSprite() {
|
public Sprite getParticleSprite() {
|
||||||
return modelSprite;
|
//TODO
|
||||||
|
return MinecraftClient.getInstance().getBakedModelManager().getMissingModel().getParticleSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSideLit() {
|
||||||
|
return false; //?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,9 +4,9 @@ import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public interface MeshTransformer extends QuadTransform {
|
public interface MeshTransformer extends QuadTransform {
|
||||||
|
@ -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.model.ModelHelper;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||||
import net.minecraft.block.BlockState;
|
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.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.render.model.json.ModelTransformation;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,13 +26,9 @@ public class SimpleModel extends AbstractModel {
|
|||||||
protected final Mesh mesh;
|
protected final Mesh mesh;
|
||||||
protected final Supplier<MeshTransformer> transformerFactory;
|
protected final Supplier<MeshTransformer> transformerFactory;
|
||||||
protected WeakReference<List<BakedQuad>[]> quadLists = null;
|
protected WeakReference<List<BakedQuad>[]> quadLists = null;
|
||||||
protected final ItemProxy itemProxy = new ItemProxy();
|
//protected final ItemProxy itemProxy = new ItemProxy();
|
||||||
|
|
||||||
public SimpleModel(
|
public SimpleModel(Mesh mesh, Supplier<MeshTransformer> transformerFactory, Sprite sprite, ModelTransformation transformation) {
|
||||||
Mesh mesh,
|
|
||||||
Supplier<MeshTransformer> transformerFactory,
|
|
||||||
Sprite sprite,
|
|
||||||
ModelTransformation transformation) {
|
|
||||||
super(sprite, transformation);
|
super(sprite, transformation);
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
this.transformerFactory = transformerFactory;
|
this.transformerFactory = transformerFactory;
|
||||||
@ -73,20 +65,21 @@ public class SimpleModel extends AbstractModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
|
public ModelOverrideList getOverrides() {
|
||||||
return itemProxy;
|
return ModelOverrideList.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class ItemProxy extends ModelItemPropertyOverrideList {
|
// @Override
|
||||||
public ItemProxy() {
|
// public ModelItemPropertyOverrideList getItemPropertyOverrides() {
|
||||||
super(null, null, null, Collections.emptyList());
|
// return itemProxy;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// protected class ItemProxy extends ModelOverrideList {
|
||||||
public BakedModel apply(BakedModel bakedModel_1, ItemStack itemStack_1, World world_1, LivingEntity livingEntity_1) {
|
// @Override
|
||||||
return SimpleModel.this;
|
// public BakedModel apply(BakedModel bakedModel_1, ItemStack itemStack_1, World world_1, LivingEntity livingEntity_1) {
|
||||||
}
|
// return SimpleModel.this;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package io.github.cottonmc.templates.model;
|
package io.github.cottonmc.templates.model;
|
||||||
|
|
||||||
import net.minecraft.client.render.model.BakedModel;
|
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.ModelBakeSettings;
|
||||||
import net.minecraft.client.render.model.ModelLoader;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.render.model.UnbakedModel;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.util.SpriteIdentifier;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
@ -22,12 +24,12 @@ public interface SimpleUnbakedModel extends UnbakedModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) {
|
default void setParents(Function<Identifier, UnbakedModel> function) {
|
||||||
return Collections.emptyList();
|
// nope
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
return bake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package io.github.cottonmc.templates.model;
|
package io.github.cottonmc.templates.model;
|
||||||
|
|
||||||
import io.github.cottonmc.templates.util.SpriteSet;
|
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.MaterialFinder;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
|
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
|
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.mesh.QuadEmitter;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
|
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
|
||||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
|
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.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.color.block.BlockColorProvider;
|
import net.minecraft.client.color.block.BlockColorProvider;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
import net.minecraft.client.render.RenderLayers;
|
||||||
import net.minecraft.client.render.model.BakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.texture.MissingSprite;
|
import net.minecraft.client.texture.MissingSprite;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
@ -23,10 +27,10 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class SlopeModel extends SimpleModel {
|
public class SlopeModel extends SimpleModel {
|
||||||
@ -34,18 +38,23 @@ public class SlopeModel extends SimpleModel {
|
|||||||
private static final ThreadLocal<Transformer> TRANSFORMERS = ThreadLocal.withInitial(Transformer::new);
|
private static final ThreadLocal<Transformer> TRANSFORMERS = ThreadLocal.withInitial(Transformer::new);
|
||||||
|
|
||||||
public SlopeModel(BlockState blockState) {
|
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) {
|
private static Mesh baseMesh(BlockState state) {
|
||||||
final MeshBuilder builder = RENDERER.meshBuilder();
|
final MeshBuilder builder = RENDERER.meshBuilder();
|
||||||
final QuadEmitter quad = builder.getEmitter();
|
final QuadEmitter quad = builder.getEmitter();
|
||||||
final Direction dir = state.get(Properties.HORIZONTAL_FACING);
|
final Direction dir = state.get(Properties.HORIZONTAL_FACING);
|
||||||
drawSlope(quad.spriteColor(0, -1, -1, -1, -1), dir);
|
drawSlope(quad.color(-1, -1, -1, -1), dir);
|
||||||
drawLeftSide(quad.spriteColor(0, -1, -1, -1, -1), dir);
|
drawLeftSide(quad.color(-1, -1, -1, -1), dir);
|
||||||
drawRightSide(quad.spriteColor(0, -1, -1, -1, -1), dir);
|
drawRightSide(quad.color(-1, -1, -1, -1), dir);
|
||||||
drawBack(quad.spriteColor(0, -1, -1, -1, -1), dir);
|
drawBack(quad.color(-1, -1, -1, -1), dir);
|
||||||
drawBottom(quad.spriteColor(0, -1, -1, -1, -1));
|
drawBottom(quad.color(-1, -1, -1, -1));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +159,14 @@ public class SlopeModel extends SimpleModel {
|
|||||||
|
|
||||||
if(block == Blocks.AIR) {
|
if(block == Blocks.AIR) {
|
||||||
sprites.clear();
|
sprites.clear();
|
||||||
material = finder.clear().blendMode(0, RenderLayer.CUTOUT).find();
|
material = finder.clear().blendMode(BlendMode.CUTOUT).find();
|
||||||
} else {
|
} 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);
|
BakedModel model = minecraft.getBlockRenderManager().getModel(template);
|
||||||
sprites.prepare(model, randomSupplier.get());
|
sprites.prepare(model, randomSupplier.get());
|
||||||
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
|
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
|
||||||
@ -181,7 +195,7 @@ public class SlopeModel extends SimpleModel {
|
|||||||
|
|
||||||
case TAG_SLOPE:
|
case TAG_SLOPE:
|
||||||
if(sprites.hasColor(Direction.UP)) {
|
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));
|
paintSlope(quad, dir, sprites.getSprite(Direction.UP));
|
||||||
break;
|
break;
|
||||||
@ -190,7 +204,7 @@ public class SlopeModel extends SimpleModel {
|
|||||||
case TAG_LEFT:
|
case TAG_LEFT:
|
||||||
final Direction leftDir = this.dir.rotateYCounterclockwise();
|
final Direction leftDir = this.dir.rotateYCounterclockwise();
|
||||||
if(sprites.hasColor(leftDir)) {
|
if(sprites.hasColor(leftDir)) {
|
||||||
quad.spriteColor(0, color, color, color, color);
|
quad.color(color, color, color, color);
|
||||||
}
|
}
|
||||||
paintLeftSide(quad, dir, sprites.getSprite(leftDir));
|
paintLeftSide(quad, dir, sprites.getSprite(leftDir));
|
||||||
break;
|
break;
|
||||||
@ -199,7 +213,7 @@ public class SlopeModel extends SimpleModel {
|
|||||||
case TAG_RIGHT: {
|
case TAG_RIGHT: {
|
||||||
final Direction rightDir = this.dir.rotateYClockwise();
|
final Direction rightDir = this.dir.rotateYClockwise();
|
||||||
if(sprites.hasColor(rightDir)) {
|
if(sprites.hasColor(rightDir)) {
|
||||||
quad.spriteColor(0, color, color, color, color);
|
quad.color(color, color, color, color);
|
||||||
}
|
}
|
||||||
paintRightSide(quad, dir, sprites.getSprite(rightDir));
|
paintRightSide(quad, dir, sprites.getSprite(rightDir));
|
||||||
break;
|
break;
|
||||||
@ -207,7 +221,7 @@ public class SlopeModel extends SimpleModel {
|
|||||||
|
|
||||||
case TAG_BACK: {
|
case TAG_BACK: {
|
||||||
if(sprites.hasColor(dir)) {
|
if(sprites.hasColor(dir)) {
|
||||||
quad.spriteColor(0, color, color, color, color);
|
quad.color(color, color, color, color);
|
||||||
}
|
}
|
||||||
paintBack(quad, dir, sprites.getSprite(dir));
|
paintBack(quad, dir, sprites.getSprite(dir));
|
||||||
break;
|
break;
|
||||||
@ -215,7 +229,7 @@ public class SlopeModel extends SimpleModel {
|
|||||||
|
|
||||||
case TAG_BOTTOM: {
|
case TAG_BOTTOM: {
|
||||||
if(sprites.hasColor(Direction.DOWN)) {
|
if(sprites.hasColor(Direction.DOWN)) {
|
||||||
quad.spriteColor(0, color, color, color, color);
|
quad.color(color, color, color, color);
|
||||||
}
|
}
|
||||||
paintBottom(quad, sprites.getSprite(Direction.DOWN));
|
paintBottom(quad, sprites.getSprite(Direction.DOWN));
|
||||||
break;
|
break;
|
||||||
@ -229,28 +243,28 @@ public class SlopeModel extends SimpleModel {
|
|||||||
private static void paintSlope(MutableQuadView quad, Direction dir, Sprite sprite) {
|
private static void paintSlope(MutableQuadView quad, Direction dir, Sprite sprite) {
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
|
quad.uv(0, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
|
.uv(1, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(2, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
|
.uv(3, sprite.getMaxU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(1, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(2, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
|
.uv(3, sprite.getMinU(), sprite.getMaxV());
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMinV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(1, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(1, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMaxV())
|
.uv(2, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(3, 0, sprite.getMaxU(), sprite.getMaxV());
|
.uv(3, sprite.getMaxU(), sprite.getMaxV());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -259,28 +273,28 @@ public class SlopeModel extends SimpleModel {
|
|||||||
private static void paintLeftSide(MutableQuadView quad, Direction dir, Sprite sprite) {
|
private static void paintLeftSide(MutableQuadView quad, Direction dir, Sprite sprite) {
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMinV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(1, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(1, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMaxV())
|
.uv(2, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(3, 0, sprite.getMaxU(), sprite.getMaxV());
|
.uv(3, sprite.getMaxU(), sprite.getMaxV());
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -289,28 +303,28 @@ public class SlopeModel extends SimpleModel {
|
|||||||
private static void paintRightSide(MutableQuadView quad, Direction dir, Sprite sprite) {
|
private static void paintRightSide(MutableQuadView quad, Direction dir, Sprite sprite) {
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(1, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(2, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
|
.uv(3, sprite.getMinU(), sprite.getMaxV());
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
|
quad.uv(0, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
|
.uv(1, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(2, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
|
.uv(3, sprite.getMaxU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
|
quad.uv(0, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV())
|
.uv(1, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(2, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(3, 0, sprite.getMaxU(), sprite.getMinV());
|
.uv(3, sprite.getMaxU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(1, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(2, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
|
.uv(3, sprite.getMinU(), sprite.getMaxV());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -319,38 +333,38 @@ public class SlopeModel extends SimpleModel {
|
|||||||
private static void paintBack(MutableQuadView quad, Direction dir, Sprite sprite) {
|
private static void paintBack(MutableQuadView quad, Direction dir, Sprite sprite) {
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(1, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(2, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
|
.uv(3, sprite.getMinU(), sprite.getMaxV());
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
quad.sprite(0, 0, sprite.getMaxU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(1, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(2, 0, sprite.getMinU(), sprite.getMinV())
|
.uv(2, sprite.getMinU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMaxV());
|
.uv(3, sprite.getMinU(), sprite.getMaxV());
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void paintBottom(MutableQuadView quad, Sprite sprite) {
|
private static void paintBottom(MutableQuadView quad, Sprite sprite) {
|
||||||
quad.sprite(0, 0, sprite.getMinU(), sprite.getMaxV())
|
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
|
||||||
.sprite(1, 0, sprite.getMaxU(), sprite.getMaxV())
|
.uv(1, sprite.getMaxU(), sprite.getMaxV())
|
||||||
.sprite(2, 0, sprite.getMaxU(), sprite.getMinV())
|
.uv(2, sprite.getMaxU(), sprite.getMinV())
|
||||||
.sprite(3, 0, sprite.getMinU(), sprite.getMinV());
|
.uv(3, sprite.getMinU(), sprite.getMinV());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.client.render.block.BlockModels;
|
import net.minecraft.client.render.block.BlockModels;
|
||||||
import net.minecraft.client.render.model.UnbakedModel;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.client.util.ModelIdentifier;
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.registry.Registries;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -28,6 +28,6 @@ public class TemplateModelVariantProvider implements ModelVariantProvider {
|
|||||||
for(BlockState state : block.getStateManager().getStates()) {
|
for(BlockState state : block.getStateManager().getStates()) {
|
||||||
variants.put(BlockModels.getModelId(state), (SimpleUnbakedModel) () -> model.apply(state));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,24 @@ import net.minecraft.client.render.model.BakedModel;
|
|||||||
import net.minecraft.client.render.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.texture.MissingSprite;
|
import net.minecraft.client.texture.MissingSprite;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class SpriteSet {
|
public class SpriteSet {
|
||||||
private Object2ObjectOpenHashMap<Direction, BakedQuad> quads = new Object2ObjectOpenHashMap<>();
|
private Object2ObjectOpenHashMap<Direction, BakedQuad> quads = new Object2ObjectOpenHashMap<>();
|
||||||
private boolean isDefault = true;
|
private boolean isDefault = true;
|
||||||
public static final Sprite DEFAULT = MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("minecraft:block/scaffolding_top"));
|
public static final Sprite DEFAULT = findSprite(new Identifier("minecraft:block/scaffolding_top"));
|
||||||
public static final Sprite FALLBACK = MissingSprite.getMissingSprite();
|
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() {
|
public SpriteSet() {
|
||||||
clear();
|
clear();
|
||||||
@ -43,16 +50,26 @@ public class SpriteSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Sprite getSprite(Direction dir) {
|
public Sprite getSprite(Direction dir) {
|
||||||
|
//TODO
|
||||||
|
if(true) return MinecraftClient.getInstance().getBakedModelManager().getMissingModel().getParticleSprite();
|
||||||
|
|
||||||
if(isDefault) return DEFAULT;
|
if(isDefault) return DEFAULT;
|
||||||
|
|
||||||
BakedQuad quad = quads.get(dir);
|
BakedQuad quad = quads.get(dir);
|
||||||
if(quad == null) return FALLBACK;
|
if(quad == null) return FALLBACK;
|
||||||
return quad.getSprite();
|
|
||||||
|
Sprite sprite = quad.getSprite();
|
||||||
|
if(sprite == null) return FALLBACK;
|
||||||
|
|
||||||
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasColor(Direction dir) {
|
public boolean hasColor(Direction dir) {
|
||||||
if(isDefault) return false;
|
if(isDefault) return false;
|
||||||
|
|
||||||
BakedQuad quad = quads.get(dir);
|
BakedQuad quad = quads.get(dir);
|
||||||
if(quad == null) return false;
|
if(quad == null) return false;
|
||||||
|
|
||||||
return quad.hasColor();
|
return quad.hasColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.4.0",
|
"minecraft": ">=1.20.1",
|
||||||
|
"fabricloader": "*",
|
||||||
|
"fabric-api": "*",
|
||||||
"fabric-renderer-indigo": "*"
|
"fabric-renderer-indigo": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user