Probably overzealous formatting commit

This commit is contained in:
quat1024 2023-06-15 01:59:48 -04:00
parent 735e79ea78
commit 5b369ab95e
18 changed files with 693 additions and 685 deletions

View File

@ -6,9 +6,12 @@ import net.fabricmc.api.ModInitializer;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.*;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.function.Supplier;
public class Templates implements ModInitializer {
@ -31,7 +34,7 @@ public class Templates implements ModInitializer {
}
@SuppressWarnings("rawtypes")
public static BlockEntityType register(String name, Supplier<BlockEntity> be, Block...blocks) {
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));
}

View File

@ -9,9 +9,10 @@ import net.minecraft.util.math.Direction;
public class TemplatesClient implements ClientModInitializer {
public static TemplateModelVariantProvider provider = new TemplateModelVariantProvider();
@Override
public void onInitializeClient() {
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider);
provider.registerTemplateModels(Templates.SLOPE, Templates.SLOPE.getDefaultState().with(SlopeBlock.FACING, Direction.SOUTH), SlopeModel::new);
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider);
provider.registerTemplateModels(Templates.SLOPE, Templates.SLOPE.getDefaultState().with(SlopeBlock.FACING, Direction.SOUTH), SlopeModel::new);
}
}

View File

@ -2,10 +2,12 @@ package io.github.cottonmc.templates.block;
import io.github.cottonmc.templates.block.entity.SlopeEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityContext;
import net.minecraft.item.*;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;

View File

@ -10,7 +10,11 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
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.Hand;
@ -30,26 +34,26 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@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;
if(world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity)) return true;
TemplateEntity be = (TemplateEntity) world.getBlockEntity(pos);
ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() instanceof BlockItem) {
Block block = ((BlockItem)stack.getItem()).getBlock();
if (block == Blocks.REDSTONE_TORCH) {
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.abilities.creativeMode) 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) {
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(!player.abilities.creativeMode) stack.decrement(1);
}
}
} else if (stack.getItem() == Items.GLOWSTONE_DUST) {
} else if(stack.getItem() == Items.GLOWSTONE_DUST) {
be.addGlowstone();
if (!player.abilities.creativeMode) stack.decrement(1);
if(!player.abilities.creativeMode) stack.decrement(1);
}
return true;
}
@ -66,21 +70,21 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@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);
if (be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be;
if (template.getRenderedState().getBlock() != Blocks.AIR) {
if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity) be;
if(template.getRenderedState().getBlock() != Blocks.AIR) {
ItemStack stack = new ItemStack(template.getRenderedState().getBlock());
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity);
}
if (template.hasRedstone()) {
if(template.hasRedstone()) {
ItemStack stack = new ItemStack(Items.REDSTONE_TORCH);
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity);
}
if (template.hasGlowstone()) {
if(template.hasGlowstone()) {
ItemStack stack = new ItemStack(Items.GLOWSTONE_DUST);
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity);
@ -92,10 +96,10 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos posFrom, boolean bool) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be;
if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity) be;
BlockState beState = template.getRenderedState();
world.setBlockState(pos, state.with(LIGHT, template.hasGlowstone()? 15 : beState.getLuminance()).with(REDSTONE, template.hasRedstone() || beState.emitsRedstonePower()));
world.setBlockState(pos, state.with(LIGHT, template.hasGlowstone() ? 15 : beState.getLuminance()).with(REDSTONE, template.hasRedstone() || beState.emitsRedstonePower()));
}
}
@ -112,9 +116,9 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override
public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
BlockEntity be = view.getBlockEntity(pos);
if (be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be;
if (template.hasRedstone()) return 15;
if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity) be;
if(template.hasRedstone()) return 15;
BlockState beState = template.getRenderedState();
return beState.getWeakRedstonePower(view, pos, dir);
}
@ -124,9 +128,9 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override
public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
BlockEntity be = view.getBlockEntity(pos);
if (be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be;
if (template.hasRedstone()) return 15;
if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity) be;
if(template.hasRedstone()) return 15;
BlockState beState = template.getRenderedState();
return beState.getStrongRedstonePower(view, pos, dir);
}
@ -136,13 +140,13 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override
public BlockState getContainedState(World world, BlockPos pos) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof TemplateEntity) return ((TemplateEntity)be).getRenderedState();
if(be instanceof TemplateEntity) return ((TemplateEntity) be).getRenderedState();
return Blocks.AIR.getDefaultState();
}
@Override
public void setContainedState(World world, BlockPos pos, BlockState state) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof TemplateEntity) ((TemplateEntity)be).setRenderedState(state);
if(be instanceof TemplateEntity) ((TemplateEntity) be).setRenderedState(state);
}
}

View File

@ -40,10 +40,10 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState"));
glowstone = tag.getBoolean("Glowstone");
redstone = tag.getBoolean("Redstone");
if (world != null && world.isClient) {
if(world != null && world.isClient) {
//TODO probably unsafe, i think the method was removed in 1.14.4 or something though
// i cant find any relevant method that takes only 1 blockpos argument
((ClientWorld)world).scheduleBlockRenders(pos.getX(), pos.getY(), pos.getZ());
((ClientWorld) world).scheduleBlockRenders(pos.getX(), pos.getY(), pos.getZ());
//world.scheduleBlockRender(pos);
}
}
@ -70,7 +70,7 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
@Override
public void markDirty() {
super.markDirty();
if (world != null && !world.isClient) {
if(world != null && !world.isClient) {
for(ServerPlayerEntity player : PlayerLookup.tracking(this)) {
player.networkHandler.sendPacket(this.toUpdatePacket());
}

View File

@ -8,40 +8,40 @@ import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
public abstract class AbstractModel implements BakedModel, FabricBakedModel {
protected static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer();
protected static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer();
protected final Sprite modelSprite;
protected final ModelTransformation transformation;
protected final Sprite modelSprite;
protected final ModelTransformation transformation;
protected AbstractModel(
Sprite sprite,
ModelTransformation transformation) {
this.modelSprite = sprite;
this.transformation = transformation;
}
protected AbstractModel(
Sprite sprite,
ModelTransformation transformation) {
this.modelSprite = sprite;
this.transformation = transformation;
}
@Override
public boolean useAmbientOcclusion() {
return true;
}
@Override
public boolean useAmbientOcclusion() {
return true;
}
@Override
public boolean hasDepth() {
return true;
}
@Override
public boolean hasDepth() {
return true;
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public Sprite getSprite() {
return modelSprite;
}
@Override
public Sprite getSprite() {
return modelSprite;
}
@Override
public ModelTransformation getTransformation() {
return transformation;
}
@Override
public ModelTransformation getTransformation() {
return transformation;
}
}

View File

@ -1,16 +1,16 @@
package io.github.cottonmc.templates.model;
import java.util.Random;
import java.util.function.Supplier;
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.world.BlockRenderView;
public interface MeshTransformer extends QuadTransform {
MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier);
import java.util.Random;
import java.util.function.Supplier;
MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier);
public interface MeshTransformer extends QuadTransform {
MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier);
MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier);
}

View File

@ -1,13 +1,6 @@
package io.github.cottonmc.templates.model;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import com.google.common.collect.ImmutableList;
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;
@ -24,82 +17,88 @@ import net.minecraft.util.math.Direction;
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;
/**
* Simple baked model supporting the Fabric Render API features.<p>
*/
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 Mesh mesh;
protected final Supplier<MeshTransformer> transformerFactory;
protected WeakReference<List<BakedQuad>[]> quadLists = null;
protected final ItemProxy itemProxy = new ItemProxy();
public SimpleModel(
Mesh mesh,
Supplier<MeshTransformer> transformerFactory,
Sprite sprite,
ModelTransformation transformation) {
super(sprite, transformation);
this.mesh = mesh;
this.transformerFactory = transformerFactory;
}
public SimpleModel(
Mesh mesh,
Supplier<MeshTransformer> transformerFactory,
Sprite sprite,
ModelTransformation transformation) {
super(sprite, transformation);
this.mesh = mesh;
this.transformerFactory = transformerFactory;
}
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public List<BakedQuad> getQuads(BlockState state, Direction face, Random rand) {
List<BakedQuad>[] lists = quadLists == null ? null : quadLists.get();
if(lists == null) {
lists = ModelHelper.toQuadLists(this.mesh);
quadLists = new WeakReference<>(lists);
}
List<BakedQuad> result = lists[face == null ? 6 : face.getId()];
return result == null ? ImmutableList.of() : result;
}
@Override
public List<BakedQuad> getQuads(BlockState state, Direction face, Random rand) {
List<BakedQuad>[] lists = quadLists == null ? null : quadLists.get();
if(lists == null) {
lists = ModelHelper.toQuadLists(this.mesh);
quadLists = new WeakReference<>(lists);
}
List<BakedQuad> result = lists[face == null ? 6 : face.getId()];
return result == null ? ImmutableList.of() : result;
}
@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
final MeshTransformer transform = transformerFactory == null ? null : transformerFactory.get().prepare(blockView, state, pos, randomSupplier);
if(transform != null) {
context.pushTransform(transform);
}
if(mesh != null) {
context.meshConsumer().accept(mesh);
}
if(transform != null) {
context.popTransform();
}
}
@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
final MeshTransformer transform = transformerFactory == null ? null : transformerFactory.get().prepare(blockView, state, pos, randomSupplier);
if(transform != null) {
context.pushTransform(transform);
}
if(mesh != null) {
context.meshConsumer().accept(mesh);
}
if(transform != null) {
context.popTransform();
}
}
@Override
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
return itemProxy;
}
@Override
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
return itemProxy;
}
protected class ItemProxy extends ModelItemPropertyOverrideList {
public ItemProxy() {
super(null, null, null, Collections.emptyList());
}
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;
}
}
@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);
if(transform != null) {
context.pushTransform(transform);
}
if(mesh != null) {
context.meshConsumer().accept(mesh);
}
if(transform != null) {
context.popTransform();
}
}
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
final MeshTransformer transform = transformerFactory == null ? null : transformerFactory.get().prepare(stack, randomSupplier);
if(transform != null) {
context.pushTransform(transform);
}
if(mesh != null) {
context.meshConsumer().accept(mesh);
}
if(transform != null) {
context.popTransform();
}
}
}

View File

@ -1,10 +1,5 @@
package io.github.cottonmc.templates.model;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
@ -12,22 +7,27 @@ import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.Identifier;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
@FunctionalInterface
public interface SimpleUnbakedModel extends UnbakedModel {
BakedModel bake();
BakedModel bake();
@Override
default Collection<Identifier> getModelDependencies() {
return Collections.emptyList();
}
@Override
default Collection<Identifier> getModelDependencies() {
return Collections.emptyList();
}
@Override
default Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) {
return Collections.emptyList();
}
@Override
default Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) {
return Collections.emptyList();
}
@Override
default BakedModel bake(ModelLoader loader, Function<Identifier, Sprite> spriteFunc, ModelBakeSettings settings) {
return bake();
}
@Override
default BakedModel bake(ModelLoader loader, Function<Identifier, Sprite> spriteFunc, ModelBakeSettings settings) {
return bake();
}
}

View File

@ -1,12 +1,5 @@
package io.github.cottonmc.templates.model;
import java.util.Random;
import java.util.function.Supplier;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.world.BlockRenderView;
import org.apache.commons.lang3.ObjectUtils;
import io.github.cottonmc.templates.util.SpriteSet;
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
@ -22,6 +15,7 @@ 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.model.BakedModel;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite;
@ -29,329 +23,334 @@ 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.world.BlockRenderView;
import org.apache.commons.lang3.ObjectUtils;
import java.util.Random;
import java.util.function.Supplier;
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) {
super(baseMesh(blockState), TRANSFORMERS::get, MissingSprite.getMissingSprite(), ModelHelper.MODEL_TRANSFORM_BLOCK);
}
public SlopeModel(BlockState blockState) {
super(baseMesh(blockState), TRANSFORMERS::get, MissingSprite.getMissingSprite(), 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));
return builder.build();
}
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));
return builder.build();
}
private static final int TAG_SLOPE = 0;
private static final int TAG_LEFT = 1;
private static final int TAG_RIGHT = 2;
private static final int TAG_BACK = 3;
private static final int TAG_BOTTOM = 4;
private static final int TAG_SLOPE = 0;
private static final int TAG_LEFT = 1;
private static final int TAG_RIGHT = 2;
private static final int TAG_BACK = 3;
private static final int TAG_BOTTOM = 4;
private static void drawSlope(QuadEmitter quad, Direction dir) {
quad.tag(TAG_SLOPE);
switch (dir) {
case NORTH:
quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 0f).emit();
break;
case SOUTH:
quad.pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 0f).emit();
break;
case EAST:
quad.pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 1f, 0f).emit();
break;
case WEST:
quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 0f).emit();
default:
break;
}
}
private static void drawSlope(QuadEmitter quad, Direction dir) {
quad.tag(TAG_SLOPE);
switch(dir) {
case NORTH:
quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 0f).emit();
break;
case SOUTH:
quad.pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 0f).emit();
break;
case EAST:
quad.pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 1f, 0f).emit();
break;
case WEST:
quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 0f).emit();
default:
break;
}
}
private static void drawLeftSide(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_LEFT).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 0f).emit();
break;
case SOUTH:
quad.tag(TAG_LEFT).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case EAST:
quad.tag(TAG_LEFT).pos(0, 1f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 0f).pos(3, 1f, 1f, 0f).emit();
break;
case WEST:
quad.tag(TAG_LEFT).pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 0f, 1f, 1f).emit();
default:
break;
}
}
private static void drawLeftSide(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_LEFT).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 0f).emit();
break;
case SOUTH:
quad.tag(TAG_LEFT).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case EAST:
quad.tag(TAG_LEFT).pos(0, 1f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 0f).pos(3, 1f, 1f, 0f).emit();
break;
case WEST:
quad.tag(TAG_LEFT).pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 0f, 1f, 1f).emit();
default:
break;
}
}
private static void drawRightSide(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_RIGHT).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 0f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case SOUTH:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 1f).emit();
break;
case EAST:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 1f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 1f).emit();
break;
case WEST:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 0f).pos(2, 1f, 0f, 0f).pos(3, 1f, 0f, 0f).emit();
default:
break;
}
}
private static void drawRightSide(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_RIGHT).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 0f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case SOUTH:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 1f).emit();
break;
case EAST:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 1f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 1f).emit();
break;
case WEST:
quad.tag(TAG_RIGHT).pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 0f).pos(2, 1f, 0f, 0f).pos(3, 1f, 0f, 0f).emit();
default:
break;
}
}
private static void drawBack(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 0f).pos(2, 1f, 1f, 0f).pos(3, 1f, 0f, 0f).emit();
break;
case SOUTH:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 0f, 1f, 1f).emit();
break;
case EAST:
quad.tag(TAG_BACK).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 0f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case WEST:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 0f, 1f, 1f).pos(3, 0f, 1f, 0f).emit();
default:
break;
}
}
private static void drawBack(QuadEmitter quad, Direction dir) {
switch(dir) {
case NORTH:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 0f).pos(2, 1f, 1f, 0f).pos(3, 1f, 0f, 0f).emit();
break;
case SOUTH:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 0f, 1f, 1f).emit();
break;
case EAST:
quad.tag(TAG_BACK).pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 0f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 1f).emit();
break;
case WEST:
quad.tag(TAG_BACK).pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 1f).pos(2, 0f, 1f, 1f).pos(3, 0f, 1f, 0f).emit();
default:
break;
}
}
private static void drawBottom(QuadEmitter quad) {
quad.tag(TAG_BOTTOM).pos(0, 0f, 0f, 0f).pos(1, 1f, 0f, 0f).pos(2, 1f, 0f, 1f).pos(3, 0f, 0f, 1f).emit();
}
private static void drawBottom(QuadEmitter quad) {
quad.tag(TAG_BOTTOM).pos(0, 0f, 0f, 0f).pos(1, 1f, 0f, 0f).pos(2, 1f, 0f, 1f).pos(3, 0f, 0f, 1f).emit();
}
private static class Transformer implements MeshTransformer {
private final MinecraftClient minecraft = MinecraftClient.getInstance();
private final SpriteSet sprites = new SpriteSet();
private final MaterialFinder finder = RENDERER.materialFinder();
private static class Transformer implements MeshTransformer {
private final MinecraftClient minecraft = MinecraftClient.getInstance();
private final SpriteSet sprites = new SpriteSet();
private final MaterialFinder finder = RENDERER.materialFinder();
private int color;
private Direction dir;
private RenderMaterial material;
private int color;
private Direction dir;
private RenderMaterial material;
@Override
public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
dir = state.get(Properties.HORIZONTAL_FACING);
color = 0xffffff;
final BlockState template = ObjectUtils.defaultIfNull((BlockState) ((RenderAttachedBlockView)blockView).getBlockEntityRenderAttachment(pos), Blocks.AIR.getDefaultState());
final Block block = template.getBlock();
@Override
public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
dir = state.get(Properties.HORIZONTAL_FACING);
color = 0xffffff;
final BlockState template = ObjectUtils.defaultIfNull((BlockState) ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos), Blocks.AIR.getDefaultState());
final Block block = template.getBlock();
if(block == Blocks.AIR) {
sprites.clear();
material = finder.clear().blendMode(0, RenderLayer.CUTOUT).find();
} else {
material = finder.clear().disableDiffuse(0, false).disableAo(0, false).blendMode(0, block.getRenderLayer()).find();
BakedModel model = minecraft.getBlockRenderManager().getModel(template);
sprites.prepare(model, randomSupplier.get());
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
if (blockColor != null) {
color = 0xff000000 | blockColor.getColor(template, blockView, pos, 1);
}
}
return this;
}
if(block == Blocks.AIR) {
sprites.clear();
material = finder.clear().blendMode(0, RenderLayer.CUTOUT).find();
} else {
material = finder.clear().disableDiffuse(0, false).disableAo(0, false).blendMode(0, block.getRenderLayer()).find();
BakedModel model = minecraft.getBlockRenderManager().getModel(template);
sprites.prepare(model, randomSupplier.get());
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
if(blockColor != null) {
color = 0xff000000 | blockColor.getColor(template, blockView, pos, 1);
}
}
return this;
}
@Override
public MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier) {
dir = Direction.NORTH;
color = 0xffffff;
sprites.clear();
material = finder.clear().find();
return this;
}
@Override
public MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier) {
dir = Direction.NORTH;
color = 0xffffff;
sprites.clear();
material = finder.clear().find();
return this;
}
@Override
public boolean transform(MutableQuadView quad) {
quad.material(material);
@Override
public boolean transform(MutableQuadView quad) {
quad.material(material);
final SpriteSet sprites = this.sprites;
switch(quad.tag()) {
final SpriteSet sprites = this.sprites;
switch(quad.tag()) {
case TAG_SLOPE:
if(sprites.hasColor(Direction.UP)) {
quad.spriteColor(0, color, color, color, color);
}
paintSlope(quad, dir, sprites.getSprite(Direction.UP));
break;
case TAG_SLOPE:
if(sprites.hasColor(Direction.UP)) {
quad.spriteColor(0, color, color, color, color);
}
paintSlope(quad, dir, sprites.getSprite(Direction.UP));
break;
case TAG_LEFT:
final Direction leftDir = this.dir.rotateYCounterclockwise();
if(sprites.hasColor(leftDir)) {
quad.spriteColor(0, color, color, color, color);
}
paintLeftSide(quad, dir, sprites.getSprite(leftDir));
break;
case TAG_LEFT:
final Direction leftDir = this.dir.rotateYCounterclockwise();
if(sprites.hasColor(leftDir)) {
quad.spriteColor(0, color, color, color, color);
}
paintLeftSide(quad, dir, sprites.getSprite(leftDir));
break;
case TAG_RIGHT: {
final Direction rightDir = this.dir.rotateYClockwise();
if(sprites.hasColor(rightDir)) {
quad.spriteColor(0, color, color, color, color);
}
paintRightSide(quad, dir, sprites.getSprite(rightDir));
break;
}
case TAG_RIGHT: {
final Direction rightDir = this.dir.rotateYClockwise();
if(sprites.hasColor(rightDir)) {
quad.spriteColor(0, color, color, color, color);
}
paintRightSide(quad, dir, sprites.getSprite(rightDir));
break;
}
case TAG_BACK: {
if(sprites.hasColor(dir)) {
quad.spriteColor(0, color, color, color, color);
}
paintBack(quad, dir, sprites.getSprite(dir));
break;
}
case TAG_BACK: {
if(sprites.hasColor(dir)) {
quad.spriteColor(0, color, color, color, color);
}
paintBack(quad, dir, sprites.getSprite(dir));
break;
}
case TAG_BOTTOM: {
if(sprites.hasColor(Direction.DOWN)) {
quad.spriteColor(0, color, color, color, color);
}
paintBottom(quad, sprites.getSprite(Direction.DOWN));
break;
}
case TAG_BOTTOM: {
if(sprites.hasColor(Direction.DOWN)) {
quad.spriteColor(0, color, color, color, color);
}
paintBottom(quad, sprites.getSprite(Direction.DOWN));
break;
}
default:
}
return true;
}
default:
}
return true;
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
default:
break;
}
}
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());
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());
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());
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());
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());
}
}
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());
}
}
}

View File

@ -1,7 +1,5 @@
package io.github.cottonmc.templates.model;
import java.util.HashMap;
import java.util.function.Function;
import net.fabricmc.fabric.api.client.model.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelVariantProvider;
@ -12,21 +10,24 @@ import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.registry.Registry;
import java.util.HashMap;
import java.util.function.Function;
public class TemplateModelVariantProvider implements ModelVariantProvider {
private final HashMap<ModelIdentifier, UnbakedModel> variants = new HashMap<>();
private final HashMap<ModelIdentifier, UnbakedModel> variants = new HashMap<>();
public TemplateModelVariantProvider() { }
public TemplateModelVariantProvider() {}
@Override
public UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException {
return variants.get(modelId);
}
@Override
public UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException {
return variants.get(modelId);
}
public void registerTemplateModels(Block block, BlockState itemState, Function<BlockState, AbstractModel> model) {
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));
}
public void registerTemplateModels(Block block, BlockState itemState, Function<BlockState, AbstractModel> model) {
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));
}
}

View File

@ -1,19 +1,18 @@
package io.github.cottonmc.templates.util;
import java.util.List;
import java.util.Random;
import net.minecraft.client.texture.MissingSprite;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.minecraft.client.MinecraftClient;
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.util.Identifier;
import net.minecraft.util.math.Direction;
import java.util.List;
import java.util.Random;
public class SpriteSet {
private Object2ObjectOpenHashMap<Direction, BakedQuad> quads = new Object2ObjectOpenHashMap<>();
private boolean isDefault = true;
@ -21,39 +20,39 @@ public class SpriteSet {
public static final Sprite FALLBACK = MissingSprite.getMissingSprite();
public SpriteSet() {
clear();
clear();
}
/** Allow re-use of instances to avoid allocation in render loop */
public void clear() {
isDefault = true;
isDefault = true;
}
/** Allow re-use of instances to avoid allocation in render loop */
//TODO: pass in block state?
public void prepare(BakedModel model, Random rand) {
this.quads.clear();
isDefault = false;
// avoid Direction.values() in hot loop - for thread safety may generate new array instances
//for (Direction dir : Direction.values()) {
for(int i = 0; i < 6; i++) {
final Direction dir = ModelHelper.faceFromIndex(i);
List<BakedQuad> quads = model.getQuads(null, dir, rand);
if (!quads.isEmpty()) this.quads.put(dir, quads.get(0));
}
}
public void prepare(BakedModel model, Random rand) {
this.quads.clear();
isDefault = false;
// avoid Direction.values() in hot loop - for thread safety may generate new array instances
//for (Direction dir : Direction.values()) {
for(int i = 0; i < 6; i++) {
final Direction dir = ModelHelper.faceFromIndex(i);
List<BakedQuad> quads = model.getQuads(null, dir, rand);
if(!quads.isEmpty()) this.quads.put(dir, quads.get(0));
}
}
public Sprite getSprite(Direction dir) {
if (isDefault) return DEFAULT;
if(isDefault) return DEFAULT;
BakedQuad quad = quads.get(dir);
if (quad == null) return FALLBACK;
if(quad == null) return FALLBACK;
return quad.getSprite();
}
public boolean hasColor(Direction dir) {
if (isDefault) return false;
BakedQuad quad = quads.get(dir);
if (quad == null) return false;
return quad.hasColor();
if(isDefault) return false;
BakedQuad quad = quads.get(dir);
if(quad == null) return false;
return quad.hasColor();
}
}

View File

@ -6,5 +6,6 @@ import net.minecraft.world.World;
public interface StateContainer {
BlockState getContainedState(World world, BlockPos pos);
void setContainedState(World world, BlockPos pos, BlockState state);
}

View File

@ -1,3 +1,3 @@
{
"block.templates.slope": "Slope Template"
"block.templates.slope": "Slope Template"
}

View File

@ -1,32 +1,32 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"minecraft:scaffolding"
]
},
"criteria": {
"has_bamboo": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "minecraft:bamboo"
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "templates:slope"
}
}
},
"requirements": [
[
"has_bamboo",
"has_the_recipe"
]
]
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"minecraft:scaffolding"
]
},
"criteria": {
"has_bamboo": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "minecraft:bamboo"
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "templates:slope"
}
}
},
"requirements": [
[
"has_bamboo",
"has_the_recipe"
]
]
}

View File

@ -1,19 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "templates:slope"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "templates:slope"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@ -1,20 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"I ",
"I~ ",
"III"
],
"key": {
"I": {
"item": "minecraft:bamboo"
},
"~": {
"item": "minecraft:string"
}
},
"result": {
"item": "templates:slope",
"count": 4
}
"type": "minecraft:crafting_shaped",
"pattern": [
"I ",
"I~ ",
"III"
],
"key": {
"I": {
"item": "minecraft:bamboo"
},
"~": {
"item": "minecraft:string"
}
},
"result": {
"item": "templates:slope",
"count": 4
}
}

View File

@ -1,26 +1,25 @@
{
"schemaVersion": 1,
"id": "templates",
"version": "$version",
"name": "Templates",
"icon": "assets/templates/icon.png",
"description": "An API for templated blocks",
"licence": "MIT",
"contact": {
"sources": "https://github.com/CottonMC/Templates"
},
"environment": "*",
"entrypoints": {
"main": [
"io.github.cottonmc.templates.Templates"
],
"client": [
"io.github.cottonmc.templates.TemplatesClient"
]
},
"depends": {
"fabricloader": ">=0.4.0",
"fabric-renderer-indigo": "*"
}
"schemaVersion": 1,
"id": "templates",
"version": "$version",
"name": "Templates",
"icon": "assets/templates/icon.png",
"description": "An API for templated blocks",
"licence": "MIT",
"contact": {
"sources": "https://github.com/CottonMC/Templates"
},
"environment": "*",
"entrypoints": {
"main": [
"io.github.cottonmc.templates.Templates"
],
"client": [
"io.github.cottonmc.templates.TemplatesClient"
]
},
"depends": {
"fabricloader": ">=0.4.0",
"fabric-renderer-indigo": "*"
}
}