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.Block;
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.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.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import java.util.function.Supplier; import java.util.function.Supplier;
public class Templates implements ModInitializer { public class Templates implements ModInitializer {
@ -31,7 +34,7 @@ public class Templates implements ModInitializer {
} }
@SuppressWarnings("rawtypes") @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)); return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, name), BlockEntityType.Builder.create(be, blocks).build(null));
} }

View File

@ -9,6 +9,7 @@ import net.minecraft.util.math.Direction;
public class TemplatesClient implements ClientModInitializer { public class TemplatesClient implements ClientModInitializer {
public static TemplateModelVariantProvider provider = new TemplateModelVariantProvider(); public static TemplateModelVariantProvider provider = new TemplateModelVariantProvider();
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider); ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider);

View File

@ -2,10 +2,12 @@ package io.github.cottonmc.templates.block;
import io.github.cottonmc.templates.block.entity.SlopeEntity; import io.github.cottonmc.templates.block.entity.SlopeEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.block.entity.BlockEntity;
import net.minecraft.entity.EntityContext; import net.minecraft.entity.EntityContext;
import net.minecraft.item.*; import net.minecraft.item.ItemPlacementContext;
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;

View File

@ -10,7 +10,11 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity; 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.BooleanProperty;
import net.minecraft.state.property.IntProperty; import net.minecraft.state.property.IntProperty;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -30,26 +34,26 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override @Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 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); 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.abilities.creativeMode) 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(Block.isShapeFullCube(placementState.getCollisionShape(world, pos)) && !(block instanceof BlockEntityProvider)) {
if (be.getRenderedState().getBlock() == Blocks.AIR) { if(be.getRenderedState().getBlock() == Blocks.AIR) {
be.setRenderedState(placementState); 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(); be.addGlowstone();
if (!player.abilities.creativeMode) stack.decrement(1); if(!player.abilities.creativeMode) stack.decrement(1);
} }
return true; return true;
} }
@ -66,21 +70,21 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override @Override
public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean bool) { 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) {
TemplateEntity template = (TemplateEntity)be; TemplateEntity template = (TemplateEntity) be;
if (template.getRenderedState().getBlock() != Blocks.AIR) { if(template.getRenderedState().getBlock() != Blocks.AIR) {
ItemStack stack = new ItemStack(template.getRenderedState().getBlock()); ItemStack stack = new ItemStack(template.getRenderedState().getBlock());
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack); ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity); world.spawnEntity(entity);
} }
if (template.hasRedstone()) { if(template.hasRedstone()) {
ItemStack stack = new ItemStack(Items.REDSTONE_TORCH); ItemStack stack = new ItemStack(Items.REDSTONE_TORCH);
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack); ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity); world.spawnEntity(entity);
} }
if (template.hasGlowstone()) { if(template.hasGlowstone()) {
ItemStack stack = new ItemStack(Items.GLOWSTONE_DUST); ItemStack stack = new ItemStack(Items.GLOWSTONE_DUST);
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack); ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(entity); world.spawnEntity(entity);
@ -92,10 +96,10 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override @Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos posFrom, boolean bool) { public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos posFrom, boolean bool) {
BlockEntity be = world.getBlockEntity(pos); BlockEntity be = world.getBlockEntity(pos);
if (be instanceof TemplateEntity) { if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be; TemplateEntity template = (TemplateEntity) be;
BlockState beState = template.getRenderedState(); 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 @Override
public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
BlockEntity be = view.getBlockEntity(pos); BlockEntity be = view.getBlockEntity(pos);
if (be instanceof TemplateEntity) { if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be; TemplateEntity template = (TemplateEntity) be;
if (template.hasRedstone()) return 15; if(template.hasRedstone()) return 15;
BlockState beState = template.getRenderedState(); BlockState beState = template.getRenderedState();
return beState.getWeakRedstonePower(view, pos, dir); return beState.getWeakRedstonePower(view, pos, dir);
} }
@ -124,9 +128,9 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override @Override
public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
BlockEntity be = view.getBlockEntity(pos); BlockEntity be = view.getBlockEntity(pos);
if (be instanceof TemplateEntity) { if(be instanceof TemplateEntity) {
TemplateEntity template = (TemplateEntity)be; TemplateEntity template = (TemplateEntity) be;
if (template.hasRedstone()) return 15; if(template.hasRedstone()) return 15;
BlockState beState = template.getRenderedState(); BlockState beState = template.getRenderedState();
return beState.getStrongRedstonePower(view, pos, dir); return beState.getStrongRedstonePower(view, pos, dir);
} }
@ -136,13 +140,13 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider
@Override @Override
public BlockState getContainedState(World world, BlockPos pos) { public BlockState getContainedState(World world, BlockPos pos) {
BlockEntity be = world.getBlockEntity(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(); return Blocks.AIR.getDefaultState();
} }
@Override @Override
public void setContainedState(World world, BlockPos pos, BlockState state) { public void setContainedState(World world, BlockPos pos, BlockState state) {
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);
} }
} }

View File

@ -40,10 +40,10 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState")); renderedState = NbtHelper.toBlockState(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) {
//TODO probably unsafe, i think the method was removed in 1.14.4 or something though //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 // 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); //world.scheduleBlockRender(pos);
} }
} }
@ -70,7 +70,7 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
@Override @Override
public void markDirty() { public void markDirty() {
super.markDirty(); super.markDirty();
if (world != null && !world.isClient) { if(world != null && !world.isClient) {
for(ServerPlayerEntity player : PlayerLookup.tracking(this)) { for(ServerPlayerEntity player : PlayerLookup.tracking(this)) {
player.networkHandler.sendPacket(this.toUpdatePacket()); player.networkHandler.sendPacket(this.toUpdatePacket());
} }

View File

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

View File

@ -1,13 +1,6 @@
package io.github.cottonmc.templates.model; 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 com.google.common.collect.ImmutableList;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; 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;
@ -24,6 +17,12 @@ import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView; import net.minecraft.world.BlockRenderView;
import net.minecraft.world.World; 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> * Simple baked model supporting the Fabric Render API features.<p>
*/ */

View File

@ -1,10 +1,5 @@
package io.github.cottonmc.templates.model; 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.BakedModel;
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;
@ -12,6 +7,11 @@ import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.Sprite;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
@FunctionalInterface @FunctionalInterface
public interface SimpleUnbakedModel extends UnbakedModel { public interface SimpleUnbakedModel extends UnbakedModel {
BakedModel bake(); BakedModel bake();

View File

@ -1,12 +1,5 @@
package io.github.cottonmc.templates.model; 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 io.github.cottonmc.templates.util.SpriteSet;
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry; import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; 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.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.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;
@ -29,6 +23,11 @@ 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.world.BlockRenderView;
import org.apache.commons.lang3.ObjectUtils;
import java.util.Random;
import java.util.function.Supplier;
public class SlopeModel extends SimpleModel { public class SlopeModel extends SimpleModel {
@ -58,7 +57,7 @@ public class SlopeModel extends SimpleModel {
private static void drawSlope(QuadEmitter quad, Direction dir) { private static void drawSlope(QuadEmitter quad, Direction dir) {
quad.tag(TAG_SLOPE); quad.tag(TAG_SLOPE);
switch (dir) { switch(dir) {
case NORTH: case NORTH:
quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 0f).emit(); quad.pos(0, 0f, 1f, 0f).pos(1, 0f, 0f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 1f, 0f).emit();
break; break;
@ -146,7 +145,7 @@ public class SlopeModel extends SimpleModel {
public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) { public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
dir = state.get(Properties.HORIZONTAL_FACING); dir = state.get(Properties.HORIZONTAL_FACING);
color = 0xffffff; color = 0xffffff;
final BlockState template = ObjectUtils.defaultIfNull((BlockState) ((RenderAttachedBlockView)blockView).getBlockEntityRenderAttachment(pos), Blocks.AIR.getDefaultState()); final BlockState template = ObjectUtils.defaultIfNull((BlockState) ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos), Blocks.AIR.getDefaultState());
final Block block = template.getBlock(); final Block block = template.getBlock();
if(block == Blocks.AIR) { if(block == Blocks.AIR) {
@ -157,7 +156,7 @@ public class SlopeModel extends SimpleModel {
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);
if (blockColor != null) { if(blockColor != null) {
color = 0xff000000 | blockColor.getColor(template, blockView, pos, 1); color = 0xff000000 | blockColor.getColor(template, blockView, pos, 1);
} }
} }
@ -228,7 +227,7 @@ 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.sprite(0, 0, sprite.getMinU(), sprite.getMinV())
.sprite(1, 0, sprite.getMinU(), sprite.getMaxV()) .sprite(1, 0, sprite.getMinU(), sprite.getMaxV())

View File

@ -1,7 +1,5 @@
package io.github.cottonmc.templates.model; 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.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException; import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelVariantProvider; import net.fabricmc.fabric.api.client.model.ModelVariantProvider;
@ -12,11 +10,14 @@ 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.util.registry.Registry;
import java.util.HashMap;
import java.util.function.Function;
public class TemplateModelVariantProvider implements ModelVariantProvider { 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 @Override
public UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException { public UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException {
@ -24,9 +25,9 @@ public class TemplateModelVariantProvider implements ModelVariantProvider {
} }
public void registerTemplateModels(Block block, BlockState itemState, Function<BlockState, AbstractModel> model) { public void registerTemplateModels(Block block, BlockState itemState, Function<BlockState, AbstractModel> model) {
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(Registry.ITEM.getId(block.asItem()), "inventory"), (SimpleUnbakedModel) () -> model.apply(itemState));
} }
} }

View File

@ -1,19 +1,18 @@
package io.github.cottonmc.templates.util; 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 it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.minecraft.client.MinecraftClient; 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.BakedQuad; import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.Sprite;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
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;
@ -39,21 +38,21 @@ public class SpriteSet {
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
final Direction dir = ModelHelper.faceFromIndex(i); final Direction dir = ModelHelper.faceFromIndex(i);
List<BakedQuad> quads = model.getQuads(null, dir, rand); List<BakedQuad> quads = model.getQuads(null, dir, rand);
if (!quads.isEmpty()) this.quads.put(dir, quads.get(0)); if(!quads.isEmpty()) this.quads.put(dir, quads.get(0));
} }
} }
public Sprite getSprite(Direction dir) { public Sprite getSprite(Direction dir) {
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(); return quad.getSprite();
} }
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();
} }
} }

View File

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

View File

@ -2,7 +2,6 @@
"schemaVersion": 1, "schemaVersion": 1,
"id": "templates", "id": "templates",
"version": "$version", "version": "$version",
"name": "Templates", "name": "Templates",
"icon": "assets/templates/icon.png", "icon": "assets/templates/icon.png",
"description": "An API for templated blocks", "description": "An API for templated blocks",