Succumb to the whims of Yarn contributors (at least compiles)

This commit is contained in:
quat1024 2023-06-15 01:53:04 -04:00
parent 5c1f64b770
commit ac61d3082c
9 changed files with 25 additions and 22 deletions

View File

@ -6,7 +6,7 @@ import net.minecraft.block.*;
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.*;
import net.minecraft.state.StateFactory; 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;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -28,11 +28,11 @@ public class SlopeBlock extends TemplateBlock {
public SlopeBlock() { public SlopeBlock() {
super(FabricBlockSettings.of(Material.WOOD).build()); super(FabricBlockSettings.of(Material.WOOD).build());
this.setDefaultState(this.getStateFactory().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));
} }
@Override @Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) { protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING, LIGHT, REDSTONE); builder.add(FACING, LIGHT, REDSTONE);
} }

View File

@ -17,7 +17,6 @@ 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;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;

View File

@ -10,9 +10,10 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; 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.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.TagHelper;
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 BlockEntityClientSerializable, RenderAttachmentBlockEntity {
@ -38,19 +39,22 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC
@Override @Override
public void fromTag(CompoundTag tag) { public void fromTag(CompoundTag tag) {
super.fromTag(tag); super.fromTag(tag);
if (tag.containsKey("BlockState", NbtType.COMPOUND)) renderedState = TagHelper.deserializeBlockState(tag.getCompound("BlockState")); if (tag.contains("BlockState", NbtType.COMPOUND)) renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState"));
else renderedState = BlockStateUtil.fromTag(tag); else renderedState = BlockStateUtil.fromTag(tag);
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) {
world.scheduleBlockRender(pos); //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());
//world.scheduleBlockRender(pos);
} }
} }
@Override @Override
public CompoundTag toTag(CompoundTag tag) { public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag); super.toTag(tag);
tag.put("BlockState", TagHelper.serializeBlockState(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; return tag;

View File

@ -26,7 +26,7 @@ public abstract class AbstractModel implements BakedModel, FabricBakedModel {
} }
@Override @Override
public boolean hasDepthInGui() { public boolean hasDepth() {
return true; return true;
} }

View File

@ -7,10 +7,10 @@ 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.ExtendedBlockView; import net.minecraft.world.BlockRenderView;
public interface MeshTransformer extends QuadTransform { public interface MeshTransformer extends QuadTransform {
MeshTransformer prepare(ExtendedBlockView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier); MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier);
MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier); MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier);
} }

View File

@ -21,7 +21,7 @@ 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.world.ExtendedBlockView; import net.minecraft.world.BlockRenderView;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@ -60,7 +60,7 @@ public class SimpleModel extends AbstractModel {
} }
@Override @Override
public void emitBlockQuads(ExtendedBlockView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) { 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); final MeshTransformer transform = transformerFactory == null ? null : transformerFactory.get().prepare(blockView, state, pos, randomSupplier);
if(transform != null) { if(transform != null) {
context.pushTransform(transform); context.pushTransform(transform);

View File

@ -3,6 +3,8 @@ package io.github.cottonmc.templates.model;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.world.BlockRenderView;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import io.github.cottonmc.templates.util.SpriteSet; import io.github.cottonmc.templates.util.SpriteSet;
@ -16,7 +18,6 @@ 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.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderLayer;
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;
@ -28,7 +29,6 @@ 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.ExtendedBlockView;
public class SlopeModel extends SimpleModel { public class SlopeModel extends SimpleModel {
@ -143,7 +143,7 @@ public class SlopeModel extends SimpleModel {
private RenderMaterial material; private RenderMaterial material;
@Override @Override
public MeshTransformer prepare(ExtendedBlockView 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());
@ -151,7 +151,7 @@ public class SlopeModel extends SimpleModel {
if(block == Blocks.AIR) { if(block == Blocks.AIR) {
sprites.clear(); sprites.clear();
material = finder.clear().blendMode(0, BlockRenderLayer.CUTOUT).find(); material = finder.clear().blendMode(0, RenderLayer.CUTOUT).find();
} else { } else {
material = finder.clear().disableDiffuse(0, false).disableAo(0, false).blendMode(0, block.getRenderLayer()).find(); material = finder.clear().disableDiffuse(0, false).disableAo(0, false).blendMode(0, block.getRenderLayer()).find();
BakedModel model = minecraft.getBlockRenderManager().getModel(template); BakedModel model = minecraft.getBlockRenderManager().getModel(template);

View File

@ -24,7 +24,7 @@ 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.getStateFactory().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

@ -3,7 +3,7 @@ package io.github.cottonmc.templates.util;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.state.StateFactory; import net.minecraft.state.StateManager;
import net.minecraft.state.property.Property; import net.minecraft.state.property.Property;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
@ -11,14 +11,14 @@ import net.minecraft.util.registry.Registry;
import java.util.Optional; import java.util.Optional;
/** /**
* use {@link net.minecraft.util.TagHelper}, which I should have been using from the start oops * use {@link net.minecraft.nbt.NbtHelper}, which I should have been using from the start oops
*/ */
@Deprecated @Deprecated
public class BlockStateUtil { public class BlockStateUtil {
public static BlockState fromTag(CompoundTag tag) { public static BlockState fromTag(CompoundTag tag) {
Block block = Registry.BLOCK.get(new Identifier(tag.getString("Block"))); Block block = Registry.BLOCK.get(new Identifier(tag.getString("Block")));
CompoundTag properties = tag.getCompound("Properties"); CompoundTag properties = tag.getCompound("Properties");
StateFactory<Block, BlockState> factory = block.getStateFactory(); StateManager<Block, BlockState> factory = block.getStateManager();
BlockState state = factory.getDefaultState(); BlockState state = factory.getDefaultState();
for (String key : properties.getKeys()) { for (String key : properties.getKeys()) {
Property<?> prop = factory.getProperty(key); Property<?> prop = factory.getProperty(key);
@ -39,7 +39,7 @@ public class BlockStateUtil {
} }
public static <T extends Comparable<T>> BlockState parseProperty(BlockState state, Property<T> property, String value) { public static <T extends Comparable<T>> BlockState parseProperty(BlockState state, Property<T> property, String value) {
Optional<T> optional = property.getValue(value); Optional<T> optional = property.parse(value);
if (optional.isPresent()) { if (optional.isPresent()) {
state = state.with(property, optional.get()); state = state.with(property, optional.get());
} }