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 2.1.1 to 1.16 #38

Open
wants to merge 3 commits into
base: 1.16_arch
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
}

architectury {
Expand All @@ -19,7 +19,7 @@ subprojects {
// The following line declares the mojmap mappings, you may use other mappings as well
// mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
}
}

Expand Down
45 changes: 45 additions & 0 deletions common/src/main/java/io/github/kosmx/bendylib/ICuboidBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.kosmx.bendylib;

import io.github.kosmx.bendylib.impl.ICuboid;

/**
* Can be passed as a lambda, get a data, returns a cuboid
*/
@FunctionalInterface
public interface ICuboidBuilder<C extends ICuboid> {

C build(Data data);

class Data{
/**
* Size parameters
*/
public float x, y, z, sizeX, sizeY, sizeZ;
public float extraX, extraY, extraZ;
public int u, v;
public boolean mirror = false;
public int textureWidth, textureHeight; //That will be int
//public float bendX, bendY, bendZ;

public Data(){}

public Data(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight){
this.u = u;
this.v = v;
this.x = x;
this.y = y;
this.z = z;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.sizeZ = sizeZ;
this.extraX = extraX;
this.extraY = extraY;
this.extraZ = extraZ;
this.mirror = mirror;
//Casting
this.textureWidth = (int) textureWidth;
this.textureHeight = (int) textureHeight;
}

}
}
31 changes: 0 additions & 31 deletions common/src/main/java/io/github/kosmx/bendylib/IModelPart.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.kosmx.bendylib;

import io.github.kosmx.bendylib.impl.DummyCuboid;
import io.github.kosmx.bendylib.impl.accessors.IModelPartAccessor;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.client.model.ModelPart;
import java.util.*;

/**
* Access to children and cuboids in {@link ModelPart}
* Don't have to reinterpret the object...
*/
public final class ModelPartAccessor {

public static ObjectList<ModelPart> getChildren(ModelPart modelPart){
return ((IModelPartAccessor)modelPart).getChildren();
}

/**
* Get a cuboid, and cast it to {@link MutableCuboid}
* Use {@link ModelPartAccessor#optionalGetCuboid(ModelPart, int)}
* @param modelPart
* @param index
* @return
*/
@Deprecated
public static MutableCuboid getCuboid(ModelPart modelPart, int index){
Optional<MutableCuboid> optionalMutableCuboid = optionalGetCuboid(modelPart, index);
return optionalMutableCuboid.orElseGet(DummyCuboid::new);
}

/**
* Get a cuboid, and cast it to {@link MutableCuboid}
*
* @param modelPart
* @param index
* @return
*/
public static Optional<MutableCuboid> optionalGetCuboid(ModelPart modelPart, int index){
if(modelPart == null || getCuboids(modelPart) == null || getCuboids(modelPart).size() <= index) return Optional.empty();
return Optional.of((MutableCuboid)getCuboids(modelPart).get(index));
}

public static List<ModelPart.Cuboid> getCuboids(ModelPart modelPart){
return ((IModelPartAccessor)modelPart).getCuboids();
}

/**
* Different workarounds to fix shared mod incompatibilities
* If needed, I advice using {@link Workaround#VanillaDraw}. that is the most stable in any modded environment.
*/
public enum Workaround {
ExportQuads, VanillaDraw, None;
}
}
56 changes: 56 additions & 0 deletions common/src/main/java/io/github/kosmx/bendylib/MutableCuboid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.kosmx.bendylib;

import io.github.kosmx.bendylib.impl.ICuboid;
import net.minecraft.util.Pair;
import org.jetbrains.annotations.Nullable;

public interface MutableCuboid {

/**
* Register a mutator to a cuboid
* @param name registration name
* @param builder ICuboid builder
* @return is the registration success
*/
boolean registerMutator(String name, ICuboidBuilder<ICuboid> builder);

/**
* Unregister a mutator
* @param name registration name
* @return could unregister something
*/
boolean unregisterMutator(String name);

/**
* Get the active mutator and its identifier
* @return null, if no active
*/
@Nullable
Pair<String, ICuboid> getActiveMutator();

/**
* Clear the current active mutator
*/
default void clearActiveMutator() {}

/**
* Get a mutator
* @param name mutator identifier
* @return null, if no mutator exists or created
*/
@Nullable
@Deprecated
//it can be removed in any future version
ICuboid getMutator(String name);

/**
* Get a mutator and make it the active
* @param name mutator identifier
* @return null, if no registered
*/
@Nullable
ICuboid getAndActivateMutator(@Nullable String name);

void copyStateFrom(MutableCuboid other);

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package io.github.kosmx.bendylib;

import io.github.kosmx.bendylib.impl.BendableCuboid;

import io.github.kosmx.bendylib.impl.ICuboid;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

/**
* You can use this to swap a ModelPart to something else.
* {@link IModelPart#mutate(MutableModelPart)} to do that
* ((IModelPart)yourModelPart).mutate(yourMutatedModelPart) will do the trick
* ModelPart to support ICuboids
*
* If you want to mutate existing Cuboids, see {@link ModelPartAccessor} and {@link MutableCuboid}
*
* {@link IModelPart#removeMutate(MutableModelPart)} to remove
* You can use is as the default modelPart in a model.
* This can be used with {@link ICuboid}.
*/
public abstract class MutableModelPart extends ModelPart {
Expand All @@ -27,6 +24,7 @@ public abstract class MutableModelPart extends ModelPart {
private MutableModelPart last = null;

protected final ObjectList<ICuboid> iCuboids = new ObjectArrayList<>();

public MutableModelPart(Model model) {
super(model);
}
Expand All @@ -43,16 +41,6 @@ public MutableModelPart(ModelPart modelPart){
this((int)modelPart.textureWidth, (int)modelPart.textureHeight, modelPart.textureOffsetU, modelPart.textureOffsetV);
}

/*
@Override
public Cuboid getRandomCuboid(Random random) {
if(this.cuboids.size() != 0) return super.getRandomCuboid(random);
else return new Cuboid()
}

*///TODO don't cause crash



@Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
Expand All @@ -73,55 +61,4 @@ public void addICuboid(ICuboid cuboid){
this.iCuboids.add(cuboid);
}

/**
* For Cross-mod compatibility
* @return the Priority level. If there is a lower level, that will be applied
* Mods like Mo'bends should use higher e.g. 5
* Mods like Emotecraft should use lover e.g. 1
*/
public int getPriority(){
return 2;
}

public boolean isActive(){
return true;
}

/**
* incompatibility finder tool
* @return the mod's name or id
*/
public abstract String modId();


//The Bendable cuboid generator code
public BendableCuboid createCuboid(int x, int y, int z, int sizeX, int sizeY, int sizeZ, float extraX, float extraY, float extraZ, Direction direction){
BendableCuboid.Builder builder = new BendableCuboid.Builder();
builder.x = x;
builder.y = y;
builder.z = z;
builder.sizeX = sizeX;
builder.sizeY = sizeY;
builder.sizeZ = sizeZ;
builder.extraX = extraX;
builder.extraY = extraY;
builder.extraZ = extraZ;
builder.direction = direction;
builder.textureWidth = (int) this.textureWidth;
builder.textureHeight = (int) this.textureHeight;
builder.u = textureOffsetU;
builder.v = textureOffsetV;
return builder.build();
}
public MutableModelPart addCuboid(int x, int y, int z, int sizeX, int sizeY, int sizeZ, float extraX, float extraY, float extraZ, Direction direction){
this.iCuboids.add(this.createCuboid(x, y, z, sizeX, sizeY, sizeZ, extraX, extraY, extraZ, direction));
return this;
}

public BendableCuboid createCuboid(int x, int y, int z, int sizeX, int sizeY, int sizeZ, float extra, Direction direction){
return this.createCuboid(x, y, z, sizeX, sizeY, sizeZ, extra, extra, extra, direction);
}
public MutableModelPart addCuboid(int x, int y, int z, int sizeX, int sizeY, int sizeZ, float extra, Direction direction){
return this.addCuboid(x, y, z, sizeX, sizeY, sizeZ, extra, extra, extra, direction);
}
}
Loading
Loading