Skip to content

Commit

Permalink
Fix server class loading issue caused by the fluid pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bennyboy1695 committed Jul 18, 2024
1 parent fcd8c94 commit 219c211
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 110 deletions.
126 changes: 51 additions & 75 deletions common/src/main/java/com/copycatsplus/copycats/CCBlocks.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.copycatsplus.copycats;

import com.tterrag.registrate.builders.BlockBuilder;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import dev.architectury.injectables.annotations.ExpectPlatform;
Expand All @@ -16,4 +17,9 @@ public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> copy
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> multiCopycat() {
throw new AssertionError("Shouldn't appear");
}

@ExpectPlatform
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> copycatBase() {
throw new AssertionError("Shouldn't appear");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.copycatsplus.copycats.foundation.copycat.model.kinetic.ICopycatPartialModel;
import com.copycatsplus.copycats.content.copycat.shaft.CopycatShaftModelCore;
import com.copycatsplus.copycats.foundation.copycat.model.kinetic.KineticCopycatRenderData;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.Property;

/**
* An enum containing all {@link ICopycatPartialModel}s.
*/
@Environment(EnvType.CLIENT)
public enum CCCopycatPartialModels implements ICopycatPartialModel {
SHAFT(new CopycatShaftModelCore(), BlockStateProperties.AXIS),
COGWHEEL(new CopycatCogWheelModelCore(), BlockStateProperties.AXIS),
Expand All @@ -39,6 +42,7 @@ public enum CCCopycatPartialModels implements ICopycatPartialModel {
private final BakedModel model;
private final Property<?>[] properties;

@Environment(EnvType.CLIENT)
@Override
public BakedModel getModel() {
return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.copycatsplus.copycats.foundation.copycat.model.assembly.AssemblyTransform;
import com.simibubi.create.content.fluids.FluidTransportBehaviour;
import com.simibubi.create.foundation.utility.Iterate;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -452,6 +454,7 @@ protected void renderComponent(CopycatRenderContext context, Direction direction
}
}

@Environment(EnvType.CLIENT)
public static class PipeModelData {
private final FluidTransportBehaviour.AttachmentTypes[] attachments;
private boolean encased;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@
import com.copycatsplus.copycats.foundation.copycat.model.assembly.CopycatRenderContext;
import com.copycatsplus.copycats.foundation.copycat.multistate.IMultiStateCopycatBlock;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.Minecraft;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.List;

import static com.copycatsplus.copycats.foundation.copycat.model.ModelUtils.getModelFor;

/**
* Block-specific but platform-independent model generation logic for copycats.
*/

public abstract class CopycatModelCore implements CopycatModelPart {

protected static final ModelEntry SUPER = new ModelEntry("super", null, null, EntryType.STATIC);

/**
* Model key for the copied material in simple copycats.
*/
@Environment(EnvType.CLIENT)
public static final String MATERIAL_KEY = "material";
protected final ModelEntry MATERIAL = new ModelEntry(MATERIAL_KEY, (state, mat) -> getModelOf(mat), this, EntryType.COPYCAT);
protected final ModelEntry KINETIC_MATERIAL = new ModelEntry(MATERIAL_KEY, (state, mat) -> getModelOf(mat), this, EntryType.KINETIC_COPYCAT);
@Environment(EnvType.CLIENT)
protected final ModelEntry MATERIAL = new ModelEntry(MATERIAL_KEY, (state, mat) -> getModelFor(mat), this, EntryType.COPYCAT);
@Environment(EnvType.CLIENT)
protected final ModelEntry KINETIC_MATERIAL = new ModelEntry(MATERIAL_KEY, (state, mat) -> getModelFor(mat), this, EntryType.KINETIC_COPYCAT);

/**
* Whether this model core should render enhanced models.
Expand All @@ -46,6 +53,7 @@ public abstract class CopycatModelCore implements CopycatModelPart {
*
* @param entries The list to register the models to.
*/
@Environment(EnvType.CLIENT)
public void registerModels(List<ModelEntry> entries) {
entries.add(MATERIAL);
}
Expand All @@ -60,6 +68,7 @@ public void registerModels(List<ModelEntry> entries) {
* @param block The multi-state copycat that this model core is meant for.
* @param isKinetic Whether the copycat is kinetic.
*/
@Environment(EnvType.CLIENT)
protected final void registerForMultiState(List<ModelEntry> entries, IMultiStateCopycatBlock block, boolean isKinetic) {
for (String property : block.storageProperties()) {
registerMultiStatePart(entries, property, isKinetic);
Expand All @@ -76,15 +85,17 @@ protected final void registerForMultiState(List<ModelEntry> entries, IMultiState
* @param property The storage property of the copycat that this model core is meant for.
* @param isKinetic Whether the copycat is kinetic.
*/
@Environment(EnvType.CLIENT)
protected final void registerMultiStatePart(List<ModelEntry> entries, String property, boolean isKinetic) {
entries.add(new ModelEntry(property, (state, mat) -> getModelOf(mat), this, isKinetic ? EntryType.KINETIC_COPYCAT : EntryType.COPYCAT));
entries.add(new ModelEntry(property, (state, mat) -> getModelFor(mat), this, isKinetic ? EntryType.KINETIC_COPYCAT : EntryType.COPYCAT));
}

/**
* Called before rendering to gather external data, such as configs, and prepare the model core for rendering.
* <p>
* This method is likely to be called on the render thread and might be called multiple times in each render.
*/
@Environment(EnvType.CLIENT)
public void prepareForRender() {
enhanced = CCConfigs.client().useEnhancedModels.get();
colorize = CCConfigs.client().colorizeMultiStates.get();
Expand All @@ -102,21 +113,10 @@ public void prepareForRender() {
* @param context The context to assemble the quads with.
* @param material The block state of the copied material. This matches the key provided for both simple and multi-state copycats.
*/
@Environment(EnvType.CLIENT)
@Override
public abstract void emitCopycatQuads(String key, BlockState state, CopycatRenderContext context, BlockState material);

/**
* Helper method to get the model of a block state.
*
* @param state The block state to get the model of.
* @return The baked model of the block state.
*/
public static BakedModel getModelOf(BlockState state) {
return Minecraft.getInstance()
.getBlockRenderer()
.getBlockModel(state);
}

/**
* Create a platform-specific {@link BakedModel} implementation for a copycat which wraps the original model and
* renders with the provided core.
Expand All @@ -126,6 +126,7 @@ public static BakedModel getModelOf(BlockState state) {
*/
@ExpectPlatform
@NotNull
@Environment(EnvType.CLIENT)
public static BakedModel createModel(BakedModel original, CopycatModelCore core) {
//noinspection DataFlowIssue
return null;
Expand All @@ -143,14 +144,24 @@ public static BakedModel createModel(BakedModel original, CopycatModelCore core)
*/
@ExpectPlatform
@NotNull
@Environment(EnvType.CLIENT)
public static BakedModel createKineticModel(BakedModel original, CopycatModelCore core) {
//noinspection DataFlowIssue
return null;
}

@Environment(EnvType.CLIENT)
@NotNull
@ExpectPlatform
public static BakedModel createFluidPipeModel(BakedModel original, CopycatModelCore copycat) {
//noinspection DataFlowIssue
return null;
}

/**
* A core that renders the original model without modifications, while still handles particles and other copycat logic.
*/
@Environment(EnvType.CLIENT)
public static final CopycatModelCore PASS_THROUGH = new CopycatModelCore() {
@Override
public void registerModels(List<ModelEntry> entries) {
Expand All @@ -168,6 +179,7 @@ public void emitCopycatQuads(String key, BlockState state, CopycatRenderContext
* <p>
* Should be used for copycats with purely kinetic parts.
*/
@Environment(EnvType.CLIENT)
public static CopycatModelCore kinetic(CopycatModelCore... cores) {
return new CopycatModelCore() {
@Override
Expand Down Expand Up @@ -216,10 +228,12 @@ public T getData() {
* @param part A {@link CopycatModelPart} to assemble the model quads with. Set to null if the model should be rendered without modifications.
* @param type The type of the model entry, which determines how the model is rendered.
*/
@Environment(EnvType.CLIENT)
public record ModelEntry(String key, @Nullable ModelGetter model, @Nullable CopycatModelPart part,
EntryType type) {
}

@Environment(EnvType.CLIENT)
public enum EntryType {
/**
* A static model that is rendered into the terrain mesh without needing the copycat material.
Expand Down Expand Up @@ -265,6 +279,7 @@ public boolean onlyWhenVirtual() {
* A functional interface to get the {@link BakedModel} when rendering a {@link ModelEntry}. For model cores with
* extra data, the data should be set before invoking this getter, so that the getter is safe to access the data.
*/
@Environment(EnvType.CLIENT)
@FunctionalInterface
public interface ModelGetter {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.copycatsplus.copycats.foundation.copycat.model;

import com.copycatsplus.copycats.utility.Platform;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

import java.util.function.Function;

@Environment(EnvType.CLIENT)
public class ModelUtils {

@SafeVarargs
@Environment(EnvType.CLIENT)
public static <Model extends CopycatModelCore> NonNullConsumer<? super Block> createKineticModel(Function<BakedModel, BakedModel> original, Model... model) {
return CreateRegistrate.blockModel(() -> m -> CopycatModelCore.createModel(original.apply(m), CopycatModelCore.kinetic(model)));
}

@Environment(EnvType.CLIENT)
public static BakedModel getModelFor(BlockState mat) {
return Platform.Environment.CLIENT.returnElseCurrent(() -> getModelOf(mat));
}

/**
* Helper method to get the model of a block state.
*
* @param state The block state to get the model of.
* @return The baked model of the block state.
*/
@Environment(EnvType.CLIENT)
public static BakedModel getModelOf(BlockState state) {
return Minecraft.getInstance()
.getBlockRenderer()
.getBlockModel(state);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.copycatsplus.copycats.foundation.copycat.model.kinetic;

import com.copycatsplus.copycats.foundation.copycat.model.CopycatModelCore;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -16,6 +18,7 @@
* <p>
* Use {@link com.jozufozu.flywheel.core.PartialModel} instead if dynamic assembly is not required.
*/
@Environment(EnvType.CLIENT)
public interface ICopycatPartialModel {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.copycatsplus.copycats.utility.BlockFaceUtils;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllTags;
import com.simibubi.create.content.contraptions.StructureTransform;
import com.simibubi.create.foundation.block.IBE;
Expand All @@ -32,7 +31,10 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.*;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.GrassColor;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class FluidPipeBlockMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")
)
private boolean onWrenched(Level instance, BlockPos pos, BlockState state, Operation<Boolean> original) {
if (state.is(AllBlocks.GLASS_FLUID_PIPE.get()) && instance.getBlockState(pos).is(CCBlocks.COPYCAT_FLUID_PIPE.get())) {
/* if (state.is(AllBlocks.GLASS_FLUID_PIPE.get()) && instance.getBlockState(pos).is(CCBlocks.COPYCAT_FLUID_PIPE.get())) {
return original.call(instance, pos, CCBlocks.COPYCAT_GLASS_FLUID_PIPE.getDefaultState()
.setValue(CopycatGlassFluidPipeBlock.AXIS, state.getValue(GlassFluidPipeBlock.AXIS))
.setValue(BlockStateProperties.WATERLOGGED, state.getValue(BlockStateProperties.WATERLOGGED)));
}
}*/
return original.call(instance, pos, state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.architectury.injectables.annotations.ExpectPlatform;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;

Expand Down Expand Up @@ -40,6 +41,22 @@ public void runIfCurrent(Supplier<Runnable> run) {
run.get().run();
}

@Nullable
public <T> T returnElseCurrent(Supplier<T> supplier) {
if (isCurrent())
return supplier.get();

return null;
}

@Nullable
public <T> T returnElseCurrent(Supplier<T> supplier, T returned) {
if (isCurrent())
return supplier.get();

return returned;
}

@ApiStatus.Internal
@ExpectPlatform
public static Environment getCurrent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.copycatsplus.copycats.fabric;

import com.copycatsplus.copycats.foundation.copycat.model.CopycatModelCore;
import com.copycatsplus.copycats.content.copycat.fluid_pipe.fabric.CopycatFluidPipeModelFabric;
import com.tterrag.registrate.providers.DataGenContext;
import com.tterrag.registrate.providers.RegistrateBlockstateProvider;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.Block;

public class CCBlocksImpl {

public static void getWrappedBlockState(DataGenContext<Block, ? extends Block> c, RegistrateBlockstateProvider p, String name) {
p.simpleBlock(c.getEntry(), p.models().withExistingParent(name, "block/barrier"));
}

public static BakedModel getFluidPipeModel(BakedModel original, CopycatModelCore copycat) {
return new CopycatFluidPipeModelFabric(original, copycat);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.copycatsplus.copycats.fabric;

import com.copycatsplus.copycats.datagen.CCBlockStateGen;
import com.copycatsplus.copycats.foundation.copycat.ICopycatBlock;
import com.copycatsplus.copycats.foundation.copycat.multistate.IMultiStateCopycatBlock;
import com.simibubi.create.AllTags;
import com.simibubi.create.foundation.data.SharedProperties;
import com.simibubi.create.foundation.data.TagGen;
import com.tterrag.registrate.builders.BlockBuilder;
Expand All @@ -10,6 +12,8 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.material.MapColor;

import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly;

public class CCBuilderTransformersImpl {

public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> copycat() {
Expand Down Expand Up @@ -39,4 +43,12 @@ public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> mult
.color(() -> IMultiStateCopycatBlock::wrappedColor)
.transform(TagGen.axeOrPickaxe());
}

public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> copycatBase() {
return b -> b.initialProperties(SharedProperties::softMetal)
.properties(p -> p.mapColor(MapColor.GLOW_LICHEN).noOcclusion())
.addLayer(() -> RenderType::cutoutMipped)
.tag(AllTags.AllBlockTags.FAN_TRANSPARENT.tag)
.transform(pickaxeOnly());
}
}
Loading

0 comments on commit 219c211

Please sign in to comment.