Skip to content

Commit

Permalink
yahoooooooo! IT WORKS!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAwesomGuy committed Jun 23, 2024
1 parent 3b0fe84 commit 9743fde
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class CottonCandyMachineBlock extends BlockWithEntity {

protected static final VoxelShape SHAPE = VoxelShapes.union(
createCuboidShape(1, 1, 1, 15, 2, 15), // base
createCuboidShape(2, 0, 2, 4, 2, 4), // feet
createCuboidShape(2, 0, 12, 4, 2, 14),
createCuboidShape(12, 0, 2, 14, 2, 4),
createCuboidShape(12, 0, 12, 14, 2, 14),
createCuboidShape(2, 0, 2, 4, 1, 4), // feet
createCuboidShape(2, 0, 12, 4, 1, 14),
createCuboidShape(12, 0, 2, 14, 1, 4),
createCuboidShape(12, 0, 12, 14, 1, 14),
createCuboidShape(0.8, 1, 1, 1.8, 3.5, 15), // outer lower
createCuboidShape(14.2, 1, 1, 15.2, 3.5, 15),
createCuboidShape(1, 1, 0.8, 15, 3.5, 1.8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

@Environment(EnvType.CLIENT)
public class CottonCandyMachineRenderer implements BlockEntityRenderer<CottonCandyMachineBlockEntity> {
public static final EntityModelLayer LAYER_LOCATION = new EntityModelLayer(CarnivalFoods.id("cotton_candy_machine"), "main");
public static final EntityModelLayer LAYER_LOCATION =
new EntityModelLayer(CarnivalFoods.id("cotton_candy_machine"), "main");
@SuppressWarnings("deprecation") // BLOCK_ATLAS_TEXTURE
public static final SpriteIdentifier TEXTURE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, CarnivalFoods.id("entity/cotton_candy_machine"));
public static final SpriteIdentifier TEXTURE =
new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, CarnivalFoods.id("entity/cotton_candy_machine"));

private final ModelPart bone;
private final ModelPart spinning;
Expand All @@ -47,40 +49,47 @@ public static TexturedModelData createBodyLayer() {
Dilation dilation1 = new Dilation(-0.01F);
Dilation dilation2 = new Dilation(-0.25F);
ModelPartBuilder
outer = create().uv(0, 8).cuboid(-7F, 2F, -6.8F, 14F, 5F, 1F), // north, east, west
outer = create().uv(0, 8).cuboid(-7F, 1.8F, -6.85F, 14F, 5F, 1F), // north, east, west
inner1 = create().uv(14, 0).cuboid(-1.5F, -0.2F, 3.3F, 3F, 5F, 1F, new Dilation(-0.2F)), // nesw
inner2 = create().cuboid(-4.2F, 0.1F, -1.35F, 1F, 5F, 3F, dilation2).mirrored(), // northeast, southeast
inner3 = create().cuboid(3.2F, 0.1F, -1.65F, 1F, 5F, 3F, dilation2); // northwest, southwest

ModelPartData bone = data.addChild(EntityModelPartNames.BONE, create(), ModelTransform.NONE);
bone.addChild("bone",
create().uv(-14, 14).cuboid(-7F, 1F, -7F, 14F, 1F, 14F, new Dilation(0.01F))
.uv(19, 4).cuboid(-6F, 0F, -6F, 2F, 2F, 2F, dilation1)
.uv(19, 4).cuboid(-6F, 0F, 4F, 2F, 2F, 2F, dilation1)
.uv(19, 4).cuboid(4F, 0F, 4F, 2F, 2F, 2F, dilation1)
.uv(19, 4).cuboid(4F, 0F, -6F, 2F, 2F, 2F, dilation1),
ModelTransform.pivot(8, 0, 8));
bone.addChild("outerN", outer, ModelTransform.rotation(PI / 180 * 7.8F, 0F, 0F));
bone.addChild("outerS", create().uv(0, 8).cuboid(-7F, 2F, 5.8F, 14F, 5F, 1F), ModelTransform.rotation(-PI / 180 * 7.8F, 0F, 0F));
bone.addChild("outerE", outer.mirrored(), ModelTransform.rotation(PI / 180 * 7.8F, HALF_PI, 0F));
bone.addChild("outerW", outer, ModelTransform.rotation(PI / 180 * 7.8F, -HALF_PI, 0F));
bone.addChild("innerE", inner1, ModelTransform.rotation(-PI / 1.125F, -PI / 36F * 11F, PI));
bone.addChild("innerW", inner1, ModelTransform.rotation(PI / 9, PI / 36F * 11F, 0F));
bone.addChild("innerN", inner1.mirrored(), ModelTransform.rotation(-PI / 1.125F, PI / 36F * 7F, PI));
bone.addChild("innerS", inner1, ModelTransform.rotation(PI / 9, -PI / 36F * 7F, 0F));
bone.addChild("innerNE", inner2, ModelTransform.rotation(-1.0601F, -1.2728F, 1.0791F));
bone.addChild("innerSE", inner2, ModelTransform.rotation(0.0375F, 0.1391F, 0.2644F));
bone.addChild("innerNW", inner3, ModelTransform.rotation(-0.0364F, 0.1348F, -0.2643F));
bone.addChild("innerSW", inner3, ModelTransform.rotation(1.0601F, -1.2728F, -1.0791F));
ModelPartData bone = data.addChild(EntityModelPartNames.BONE, create(), ModelTransform.pivot(8, 0, 8));
bone.addChild("base",
create().uv(-14, 14).cuboid(-7F, 1F, -7F, 14F, 1F, 14F, new Dilation(0.01F))
.uv(20, 4).cuboid(-6F, 0F, -6F, 2F, 2F, 2F, dilation1)
.uv(20, 4).cuboid(-6F, 0F, 4F, 2F, 2F, 2F, dilation1)
.uv(20, 4).cuboid(4F, 0F, 4F, 2F, 2F, 2F, dilation1)
.uv(20, 4).cuboid(4F, 0F, -6F, 2F, 2F, 2F, dilation1),
ModelTransform.NONE);
bone.addChild("outerN", outer, ModelTransform.rotation(PI / 180 * -7.6F, 0F, 0F));
bone.addChild("outerS", create().uv(0, 8).cuboid(-7F, 1.8F, 5.85F, 14F, 5F, 1F),
ModelTransform.rotation(PI / 180 * 7.6F, 0F, 0F));
bone.addChild("outerE", outer.mirrored(), ModelTransform.rotation(PI / 180 * -7.6F, HALF_PI, 0F));
bone.addChild("outerW", outer, ModelTransform.rotation(PI / 180 * -7.6F, -HALF_PI, 0F));
bone.addChild("innerE", inner1, ModelTransform.rotation(PI / 1.125F, -PI / 36F * 11F, -PI));
bone.addChild("innerW", inner1, ModelTransform.rotation(PI / -9, PI / 36F * 11F, 0F));
bone.addChild("innerN", inner1.mirrored(), ModelTransform.rotation(PI / 1.125F, PI / 36F * 7F, -PI));
bone.addChild("innerS", inner1, ModelTransform.rotation(PI / -9, PI / -36F * 7F, 0F));
bone.addChild("innerNE", inner2, ModelTransform.rotation(1.0601F, -1.2728F, -1.0791F));
bone.addChild("innerSE", inner2, ModelTransform.rotation(-0.0375F, 0.1391F, -0.2644F));
bone.addChild("innerNW", inner3, ModelTransform.rotation(0.0364F, 0.1348F, 0.2643F));
bone.addChild("innerSW", inner3, ModelTransform.rotation(-1.0601F, -1.2728F, 1.0791F));

data.addChild("spinning", create().uv(8, 0).cuboid(7F, 1.3F, 7.5F, 2F, 4F, 1F), ModelTransform.rotation(0F, -PI / 7.9F, 0F));
data.addChild("spinning", create().uv(8, 0).cuboid(-1F, 1.3F, -0.5F, 2F, 4F, 1F),
ModelTransform.of(8, 0, 8, 0F, PI / -7.9F, 0F));

return TexturedModelData.of(modelData, 32, 32);
}

@Override
public void render(CottonCandyMachineBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
public void render(CottonCandyMachineBlockEntity entity, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light, int overlay) {
spinning.yaw = (spinning.yaw + tickDelta) % PI;
renderStationary(matrices, vertexConsumers, light, overlay);
}

public void renderStationary(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
VertexConsumer consumer = TEXTURE.getVertexConsumer(vertexConsumers, RenderLayer::getEntityCutout);
bone.render(matrices, consumer, light, overlay);
spinning.render(matrices, consumer, light, overlay);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.anawesomguy.carnivalfoods.internal;

import org.jetbrains.annotations.ApiStatus.Internal;

@Internal
public interface JsonUnbakedModelExtensions {
void carnival_foods$setInherit(boolean inherit);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package net.anawesomguy.carnivalfoods.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.anawesomguy.carnivalfoods.client.CarnivalFoodsClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemModels;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemRenderer.class)
public abstract class ItemRendererMixin {
@WrapOperation(method = "getModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemModels;getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel renderHeldItem(ItemModels models, ItemStack stack, Operation<BakedModel> original) {
Identifier modelId = CarnivalFoodsClient.HELD_ITEM_MODELS.get(stack.getItem());
if (modelId != null)
return models.getModelManager().getModel(modelId);
return original.call(models, stack);
@Shadow @Final
private ItemModels models;

@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/BakedModel;getTransformation()Lnet/minecraft/client/render/model/json/ModelTransformation;"))
private void getHeldItemModel(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded,
MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay,
BakedModel model, CallbackInfo ci, @Local(ordinal = 1) boolean bl, @Local(argsOnly = true) LocalRef<BakedModel> modelRef) {
if (!bl) {
BakedModel heldModel = models.getModelManager().getModel(CarnivalFoodsClient.HELD_ITEM_MODELS.get(stack.getItem()));
if (heldModel != null)
modelRef.set(heldModel);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.anawesomguy.carnivalfoods.mixin;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.llamalad7.mixinextras.sugar.Local;
import net.anawesomguy.carnivalfoods.internal.JsonUnbakedModelExtensions;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.render.model.json.ModelElement;
Expand All @@ -25,7 +26,7 @@
import java.util.function.Function;

@Mixin(JsonUnbakedModel.class)
public abstract class JsonUnbakedModelMixin implements UnbakedModel {
public abstract class JsonUnbakedModelMixin implements JsonUnbakedModelExtensions {
@Shadow @Final
private List<ModelElement> elements;
@Unique
Expand All @@ -39,17 +40,29 @@ public abstract class JsonUnbakedModelMixin implements UnbakedModel {
) // targets right before the for loop loops over, after `parent` is set
private void addInheritedElements(Function<Identifier, UnbakedModel> modelLoader, CallbackInfo ci, @Local JsonUnbakedModel jsonModel, @Local UnbakedModel unbakedModel) {
JsonUnbakedModelMixin jsonModelMixin = (JsonUnbakedModelMixin)(Object)jsonModel;
if (jsonModelMixin.inheritElements && !jsonModelMixin.elements.isEmpty())
jsonModelMixin.elements.addAll(((JsonUnbakedModel)unbakedModel).getElements());

if (jsonModelMixin.inheritElements && !jsonModelMixin.elements.isEmpty()) {
List<ModelElement> parentElements = ((JsonUnbakedModel)unbakedModel).getElements();
int parentSize = parentElements.size();
if (parentSize == 1)
jsonModelMixin.elements.add(parentElements.getFirst());
else if (parentSize > 1)
jsonModelMixin.elements.addAll(((JsonUnbakedModel)unbakedModel).getElements());
}
}

@Override
public void carnival_foods$setInherit(boolean inheritElements) {
this.inheritElements = inheritElements;
}

@Mixin(JsonUnbakedModel.Deserializer.class)
public static abstract class DeserializerMixin implements JsonDeserializer<JsonUnbakedModel> {
@SuppressWarnings("ReferenceToMixin") // it's in a mixin
public static abstract class DeserializerMixin {
@Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;", at = @At("RETURN"))
private void setInheritElements(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable<JsonUnbakedModel> cir) {
((JsonUnbakedModelMixin)(Object)cir.getReturnValue()).inheritElements =
((JsonObject)jsonElement).getAsJsonPrimitive("inherit_elements").getAsBoolean();
JsonPrimitive inherit = ((JsonObject)jsonElement).getAsJsonPrimitive("inherit_elements");
if (inherit != null)
((JsonUnbakedModelExtensions)cir.getReturnValue()).carnival_foods$setInherit(inherit.getAsBoolean());
}
}
}
Binary file removed src/main/resources/assets/carnival-foods/icon.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"parent": "item/generated",
"textures": {
"layer0": "item/stick",
"layer1": "item/wooden_shovel"
"layer1": "carnival-foods:item/cotton_candy"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"issues": "${github_repo}/issues"
},
"license": "Apache-2.0",
"icon": "assets/carnival-foods/icon.png",
"environment": "*",
"entrypoints": {
"main": [
Expand Down

0 comments on commit 9743fde

Please sign in to comment.