Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to 1.19.2 #151

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mc_version=1.18.2
forge_version=40.0.19
mod_version=3.1.1
mc_version=1.19.2
forge_version=43.2.0
mod_version=3.2.0

ccl_version=4.1.4.+
ccl_version=4.3.2.+
ccl_version_max=5.0.0

mixin_version=2.0.0.20
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/codechicken/microblock/api/BlockMicroMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraftforge.common.TierSortingRegistry;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -50,11 +51,6 @@ public BlockMicroMaterial(Block block) {

public BlockMicroMaterial(BlockState state) {
this.state = state;
setRegistryName();
}

protected void setRegistryName() {
setRegistryName(makeMaterialKey(state));
}

@Override
Expand Down Expand Up @@ -113,11 +109,8 @@ public RenderType getItemRenderLayer() {
}

@Override
public boolean renderCuboids(CCRenderState ccrs, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids) {
if (layer == null || ItemBlockRenderTypes.canRenderInLayer(state, layer)) {
return MicroblockRender.renderCuboids(ccrs, state, layer, cuboids);
}
return false;
public void renderCuboids(CCRenderState ccrs, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids) {
MicroblockRender.renderCuboids(ccrs, state, layer, cuboids);
}

@Override
Expand Down Expand Up @@ -186,7 +179,7 @@ private TextureAtlasSprite getSprite(Level level, BlockPos pos) {
*/
public static ResourceLocation makeMaterialKey(BlockState state) {
Block block = state.getBlock();
StringBuilder path = new StringBuilder(block.getRegistryName().getPath());
StringBuilder path = new StringBuilder(ForgeRegistries.BLOCKS.getKey(block).getPath());
if (!state.getProperties().isEmpty()) {
path.append("//");

Expand All @@ -198,6 +191,6 @@ public static ResourceLocation makeMaterialKey(BlockState state) {
path.append(property.getName()).append('.').append(property.getName(unsafeCast(entry.getValue())));
}
}
return new ResourceLocation(block.getRegistryName().getNamespace(), path.toString());
return new ResourceLocation(ForgeRegistries.BLOCKS.getKey(block).getNamespace(), path.toString());
}
}
13 changes: 11 additions & 2 deletions src/main/java/codechicken/microblock/api/MicroMaterial.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package codechicken.microblock.api;

import codechicken.microblock.util.MicroMaterialRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
Expand All @@ -11,15 +13,15 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.ForgeRegistryEntry.UncheckedRegistryEntry;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.Consumer;

/**
* Created by covers1624 on 26/6/22.
*/
public abstract class MicroMaterial extends UncheckedRegistryEntry<MicroMaterial> {
public abstract class MicroMaterial {

@Nullable
Object renderProperties;
Expand All @@ -28,6 +30,13 @@ public MicroMaterial() {
initClient();
}

/**
* @return Key this material is registered under
*/
public ResourceLocation getRegistryName() {
return Objects.requireNonNull(MicroMaterialRegistry.MICRO_MATERIALS.getKey(this));
}

/**
* @return If this material is not opaque. (Glass, Ice, etc.)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static MicroMaterialClient get(MicroMaterial material) {

public abstract RenderType getItemRenderLayer();

public abstract boolean renderCuboids(CCRenderState ccrs, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids);
public abstract void renderCuboids(CCRenderState ccrs, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids);

public void renderDynamic(MicroblockPart part, @Nullable ItemTransforms.TransformType transformType, PoseStack pStack, MultiBufferSource buffers, int packedLight, int packedOverlay, float partialTicks) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public class MicroBlockPartRenderer implements PartRenderer<MicroblockPart> {
public static final MicroBlockPartRenderer INSTANCE = new MicroBlockPartRenderer();

@Override
public boolean renderStatic(MicroblockPart part, @Nullable RenderType layer, CCRenderState ccrs) {
public void renderStatic(MicroblockPart part, @Nullable RenderType layer, CCRenderState ccrs) {
MicroMaterialClient clientMaterial = MicroMaterialClient.get(part.material);
if (clientMaterial != null) {
return clientMaterial.renderCuboids(ccrs, layer, part.getRenderCuboids(false));
clientMaterial.renderCuboids(ccrs, layer, part.getRenderCuboids(false));
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package codechicken.microblock.client;

import codechicken.lib.model.PerspectiveModelState;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.item.IItemRenderer;
import codechicken.lib.util.TransformUtils;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.api.MicroMaterial;
import codechicken.microblock.api.MicroMaterialClient;
import codechicken.microblock.part.StandardMicroFactory;
import codechicken.microblock.item.ItemMicroBlock;
import codechicken.microblock.part.MicroblockPart;
import codechicken.microblock.part.StandardMicroFactory;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.world.item.ItemStack;

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ public void renderItem(ItemStack stack, ItemTransforms.TransformType transformTy
}

@Override
public ModelState getModelTransform() {
public PerspectiveModelState getModelState() {
return TransformUtils.DEFAULT_BLOCK;
}

Expand Down
36 changes: 17 additions & 19 deletions src/main/java/codechicken/microblock/client/MicroblockRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -45,15 +46,13 @@
import net.minecraft.world.level.lighting.LevelLightEngine;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.client.event.DrawSelectionEvent;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.event.RenderHighlightEvent;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
import org.jetbrains.annotations.Nullable;

import java.util.OptionalDouble;
import java.util.Random;

import static codechicken.microblock.CBMicroblock.MOD_ID;

Expand Down Expand Up @@ -89,7 +88,7 @@ public static void init() {
MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, MicroblockRender::onDrawHighlight);
}

private static void onDrawHighlight(DrawSelectionEvent.HighlightBlock event) {
private static void onDrawHighlight(RenderHighlightEvent.Block event) {
Camera camera = event.getCamera();
if (camera.getEntity() instanceof Player player) {
ItemStack stack = player.getMainHandItem();
Expand All @@ -101,7 +100,7 @@ private static void onDrawHighlight(DrawSelectionEvent.HighlightBlock event) {
PoseStack pStack = event.getPoseStack();
pStack.pushPose();
pStack.translate(-camera.getPosition().x, -camera.getPosition().y, -camera.getPosition().z);
if (renderHighlight(player, InteractionHand.MAIN_HAND, stack, event.getTarget(), pStack, event.getMultiBufferSource(), event.getPartialTicks())) {
if (renderHighlight(player, InteractionHand.MAIN_HAND, stack, event.getTarget(), pStack, event.getMultiBufferSource(), event.getPartialTick())) {
event.setCanceled(true);
}

Expand Down Expand Up @@ -168,10 +167,10 @@ private static void transformFace(Vector3 hit, int side, Matrix4 mat) {
mat.translate(0, rHit.y - 0.002, 0);
}

public static boolean renderCuboids(CCRenderState ccrs, BlockState state, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids) {
public static void renderCuboids(CCRenderState ccrs, BlockState state, @Nullable RenderType layer, Iterable<MaskedCuboid> cuboids) {
PipelineState pipeState = PIPELINES.get();
BakedVertexSource vertexSource = BakedVertexSource.instance();
Random randy = new Random();
RandomSource randy = RandomSource.create();

BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
BlockColors blockColors = Minecraft.getInstance().getBlockColors();
Expand All @@ -180,29 +179,29 @@ public static boolean renderCuboids(CCRenderState ccrs, BlockState state, @Nulla
BlockPos pos = null;
long seed = 42L;
BlockAndTintGetter level = null;
IModelData modelData = EmptyModelData.INSTANCE;
ModelData modelData = ModelData.EMPTY;
if (layer != null) {
pos = ccrs.lightMatrix.pos;
seed = state.getSeed(pos);
level = new MicroblockLevelProxy(ccrs.lightMatrix.access, pos, state);
modelData = model.getModelData(level, pos, state, modelData);

if (!model.getRenderTypes(state, randy, modelData).contains(layer)) return;
}

boolean ret = false;
for (Direction face : Direction.BY_3D_DATA) {
randy.setSeed(seed);
for (BakedQuad quad : model.getQuads(state, face, randy, modelData)) {
ret |= renderQuad(ccrs, vertexSource, pipeState, blockColors, layer, quad, state, level, pos, cuboids);
for (BakedQuad quad : model.getQuads(state, face, randy, modelData, layer)) {
renderQuad(ccrs, vertexSource, pipeState, blockColors, layer, quad, state, level, pos, cuboids);
}
}
randy.setSeed(seed);
for (BakedQuad quad : model.getQuads(state, null, randy, modelData)) {
ret |= renderQuad(ccrs, vertexSource, pipeState, blockColors, layer, quad, state, level, pos, cuboids);
for (BakedQuad quad : model.getQuads(state, null, randy, modelData, layer)) {
renderQuad(ccrs, vertexSource, pipeState, blockColors, layer, quad, state, level, pos, cuboids);
}
return ret;
}

private static boolean renderQuad(CCRenderState ccrs, BakedVertexSource vs, PipelineState pipeState, BlockColors blockColors, @Nullable RenderType layer, BakedQuad quad, BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, Iterable<MaskedCuboid> cuboids) {
private static void renderQuad(CCRenderState ccrs, BakedVertexSource vs, PipelineState pipeState, BlockColors blockColors, @Nullable RenderType layer, BakedQuad quad, BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, Iterable<MaskedCuboid> cuboids) {
BakedPipeline pipeline = pipeState.pipeline;
QuadClamper clamper = pipeState.clamper;
QuadFaceStripper faceStripper = pipeState.faceStripper;
Expand All @@ -223,18 +222,17 @@ private static boolean renderQuad(CCRenderState ccrs, BakedVertexSource vs, Pipe
pipeline.setElementState("tinter", quad.isTinted());

pipeline.prepare(vs);
quad.pipe(pipeline);
pipeline.put(quad);
}

if (vs.getVertexCount() <= 0) return false;
if (vs.getVertexCount() <= 0) return;

ccrs.setModel(vs);
if (layer != null) {
ccrs.render(ccrs.lightMatrix);
} else {
ccrs.render();
}
return true;
}

// Exists as a mixin target for mods which change the vertex formats.
Expand Down
Loading
Loading