diff --git a/build.gradle b/build.gradle index aaaf5840..b4a47ee9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,97 +3,92 @@ plugins { id 'io.github.ladysnake.chenille' version '0.11.3' } -archivesBaseName = project.archives_base_name +base { + archivesName = project.archives_base_name +} + version = project.version group = project.maven_group -repositories { - mavenLocal() - // publishing - maven { - name = "CurseForge" - url = "https://minecraft.curseforge.com/api/maven" +loom { + mods { + "ratsmischief" { + sourceSet sourceSets.main + } } +} - // cloth config - maven { url "https://maven.shedaniel.me/" } +repositories { + mavenLocal() // CCA, Requiem chenille.repositories.ladysnake() - // mod menu - maven { - name = 'TerraformersMC' - url = 'https://maven.terraformersmc.com/' - } + // Mod Menu + maven { url = "https://maven.terraformersmc.com/" } - maven { url 'https://jitpack.io' } + // GeckoLib + maven { url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/" } - maven { - name "modrinth" - url "https://api.modrinth.com/maven" - } - - maven { url 'https://masa.dy.fi/maven' } - - maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' } - - // mialee misc - maven { url "https://maven.willbl.dev/releases" } + // MialeeMisc + maven { url = "https://maven.willbl.dev/releases/" } + // Publishing maven { - url = 'https://maven.jamieswhiteshirt.com/libs-release/' - content { - includeGroup 'com.jamieswhiteshirt' - } + name = "CurseForge" + url = "https://minecraft.curseforge.com/api/maven" } - maven { - url = 'https://oss.sonatype.org/content/repositories/snapshots' - content { - includeGroup 'me.lucko' - } + name = "Modrinth" + url = "https://api.modrinth.com/maven" } - // ears - maven { url "https://repo.unascribed.com" } + mavenCentral() + maven { url = "https://jitpack.io" } } dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:intermediary-v2" - modImplementation "software.bernie.geckolib:${project.geckolib_version}" - modImplementation "org.quiltmc:quilt-loader:${project.loader_version}" modImplementation "org.quiltmc:qsl:${qsl_version}+${minecraft_version}" modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${quilted_fabric_api_version}-${minecraft_version}" - // reach attributes - modImplementation("com.github.emilyploszaj:step-height-entity-attribute:v1.0.1") - include("com.github.emilyploszaj:step-height-entity-attribute:v1.0.1") + modImplementation("software.bernie.geckolib:${project.geckolib_version}") { + exclude group: 'net.fabricmc' + exclude group: 'net.fabricmc.fabric-api' + } - // mod menu - modLocalImplementation("com.terraformersmc:modmenu:${mod_menu_version}") { transitive = false } + // SHEA + modImplementation include("com.github.emilyploszaj:step-height-entity-attribute:${project.shea_version}") { + exclude group: 'net.fabricmc' + exclude group: 'net.fabricmc.fabric-api' + } - // mixin extras - implementation include("com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}") - annotationProcessor("com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}") + // Mod Menu + modLocalRuntime("com.terraformersmc:modmenu:${mod_menu_version}") { + transitive = false + } - // mialee misc - modImplementation include("xyz.amymialee:mialeemisc:${project.mialeemisc_version}") + // MialeeMisc + //modImplementation include("xyz.amymialee:mialeemisc:${project.mialeemisc_version}") - // ok zoomer -// runtimeOnly("com.github.EnnuiL:OkZoomer:1.19.2-SNAPSHOT") + // CCA + //modCompileOnly include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}") - modCompileOnly("io.github.ladysnake:PlayerAbilityLib:${project.pal_version}") - modImplementation("io.github.ladysnake:requiem-api:${project.requiem_version}") - modImplementation("io.github.ladysnake:requiem-core:${project.requiem_version}") - modImplementation include("io.github.ladysnake:requiem-lite:${project.requiem_version}") + // Requiem + //modCompileOnly("io.github.ladysnake:PlayerAbilityLib:${project.pal_version}") + //modImplementation("io.github.ladysnake:requiem-api:${project.requiem_version}") + //modImplementation("io.github.ladysnake:requiem-core:${project.requiem_version}") + //modImplementation include("io.github.ladysnake:requiem-lite:${project.requiem_version}") - // trinkets - modImplementation ("dev.emi:trinkets:${project.trinkets_version}") + // Trinkets + modImplementation("dev.emi:trinkets:${project.trinkets_version}") { + exclude group: 'net.fabricmc' + exclude group: 'net.fabricmc.fabric-api' + } } chenille { @@ -122,6 +117,6 @@ java { // If you plan to use a different file for the license, don't forget to change the file name here! jar { from('LICENSE') { - rename { "${it}_${archivesBaseName}" } + rename { "${it}_${project.base.archivesName.get()}" } } } diff --git a/gradle.properties b/gradle.properties index 516d90e1..30ff85e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,33 +7,25 @@ version = 2.0.1 maven_group = ladysnake archives_base_name = ratsmischief -minecraft_version=1.19.2 -quilt_mappings=22 +minecraft_version = 1.20.1 +quilt_mappings = 23 -loader_version=0.19.2-beta.2 +loader_version = 0.26.0 # QSL -# QSL version number is shared between all the modules. -qsl_version = 3.0.0-beta.29 +qsl_version = 6.1.2 # Quilted Fabric API -quilted_fabric_api_version = 4.0.0-beta.30+0.76.0 +quilted_fabric_api_version = 7.5.0+0.92.2 #Mod Depencencies -mod_menu_version=4.1.2 -cca_version=5.0.2 -carpet_version=1.19.1-1.4.83+v220727 -geckolib_version=geckolib-quilt-1.19:3.1.41 -mixin_extras_version=0.2.0-beta.4 -mialeemisc_version=1.0.39 -pal_version = 1.6.0 -requiem_version = 2.0.0-beta.16.stripped -automatone_version = 0.9.0 -impersonate_version = 2.8.0 -satin_version = 1.9.0 -fiber_version = 0.23.0-2 -trinkets_version=3.4.1 -elegantarmour_version=1.0-SNAPSHOT +mod_menu_version = 7.2.2 +cca_version = 5.2.2 +geckolib_version = geckolib-fabric-1.20.1:4.4.6 +mialeemisc_version = 1.0.38 +pal_version = 1.8.0 +shea_version = v1.2.0 +trinkets_version = 3.7.2 # Release metadata modrinth_id = Jjc1149h diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd491..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22ce..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a42..b740cf13 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. diff --git a/settings.gradle b/settings.gradle index d969e342..279c7726 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,11 +4,11 @@ pluginManagement { name = 'Quilt' url = 'https://maven.quiltmc.org/repository/release' } - // Currently needed for Intermediary and other temporary dependencies maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + mavenCentral() gradlePluginPortal() } } diff --git a/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClient.java b/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClient.java index 0182138d..ac959330 100644 --- a/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClient.java +++ b/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClient.java @@ -1,31 +1,27 @@ package ladysnake.ratsmischief.client; import ladysnake.ratsmischief.client.render.entity.RatEntityRenderer; -import ladysnake.ratsmischief.client.render.item.RatItemRenderer; import ladysnake.ratsmischief.client.render.item.RatMasterMaskItemRenderer; import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.init.ModEntities; import ladysnake.ratsmischief.common.init.ModItems; import ladysnake.ratsmischief.common.init.ModParticles; -import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; -import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry; -import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.model.Dilation; import net.minecraft.client.model.TexturedModelData; import net.minecraft.client.render.entity.model.EntityModelLayer; import net.minecraft.client.render.entity.model.PlayerEntityModel; import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.registry.Registries; import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; -import software.bernie.geckolib3.renderers.geo.GeoItemRenderer; -import xyz.amymialee.mialeemisc.MialeeMiscClient; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; public class RatsMischiefClient implements ClientModInitializer { public static final EntityModelLayer RAT_MASTER_ARMOR_INNER_LAYER = new EntityModelLayer(RatsMischief.id("rat_master_inner_layer"), "main"); @@ -46,21 +42,18 @@ public void onInitializeClient(ModContainer mod) { ModParticles.init(); EntityRendererRegistry.register(ModEntities.RAT, RatEntityRenderer::new); - GeoItemRenderer.registerItemRenderer(ModItems.RAT, new RatItemRenderer()); - Identifier itemId = Registry.ITEM.getId(ModItems.RAT_MASTER_MASK); + Identifier itemId = Registries.ITEM.getId(ModItems.RAT_MASTER_MASK); RatMasterMaskItemRenderer inventoryItemRenderer = new RatMasterMaskItemRenderer(itemId); - ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(inventoryItemRenderer); + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(inventoryItemRenderer); BuiltinItemRendererRegistry.INSTANCE.register(ModItems.RAT_MASTER_MASK, inventoryItemRenderer); - ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> { - out.accept(new ModelIdentifier(itemId, "inventory")); - out.accept(new ModelIdentifier(itemId + "_worn", "inventory")); - }); - MialeeMiscClient.INVENTORY_ITEMS.add(ModItems.RAT_MASTER_MASK); + ModelLoadingPlugin.register(pluginContext -> { + pluginContext.addModels(new ModelIdentifier(itemId, "inventory")); + pluginContext.addModels(new ModelIdentifier(new Identifier(itemId.getNamespace(), itemId.getPath() + "_worn"), "inventory")); + }); // model predicates - FabricModelPredicateProviderRegistry.register(new Identifier(RatsMischief.MOD_ID + ":filled"), (itemStack, world, livingEntity, seed) -> itemStack.getOrCreateSubNbt(RatsMischief.MOD_ID).getFloat("filled")); - + ModelPredicateProviderRegistry.register(RatsMischief.id("filled"), (itemStack, world, livingEntity, seed) -> itemStack.getOrCreateSubNbt(RatsMischief.MOD_ID).getFloat("filled")); // // block render layer map // BlockRenderLayerMap.put(RenderLayer.getCutout(), ModBlock.MOD_BLOCK); diff --git a/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClientHelper.java b/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClientHelper.java index 6cb997ea..6f8efe5a 100644 --- a/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClientHelper.java +++ b/src/main/java/ladysnake/ratsmischief/client/RatsMischiefClientHelper.java @@ -20,7 +20,7 @@ public static void addSetBonus(List tooltip) { public static boolean shouldRatsBringItems() { PlayerEntity player = MinecraftClient.getInstance().player; if (player instanceof PlayerRatOwner playerRatOwner) { - return playerRatOwner.shouldBringItems(); + return playerRatOwner.mischief$shouldBringItems(); } return false; } diff --git a/src/main/java/ladysnake/ratsmischief/client/model/RatEntityModel.java b/src/main/java/ladysnake/ratsmischief/client/model/RatEntityModel.java index fe5441f2..6cd87cdc 100644 --- a/src/main/java/ladysnake/ratsmischief/client/model/RatEntityModel.java +++ b/src/main/java/ladysnake/ratsmischief/client/model/RatEntityModel.java @@ -5,13 +5,13 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import software.bernie.geckolib3.core.event.predicate.AnimationEvent; -import software.bernie.geckolib3.core.processor.IBone; -import software.bernie.geckolib3.model.AnimatedGeoModel; +import software.bernie.geckolib.core.animatable.model.CoreGeoBone; +import software.bernie.geckolib.core.animation.AnimationState; +import software.bernie.geckolib.model.GeoModel; -public class RatEntityModel extends AnimatedGeoModel { - private static final Identifier MODEL = new Identifier(RatsMischief.MOD_ID, "geo/entity/rat.geo.json"); - private static final Identifier ANIMATION = new Identifier(RatsMischief.MOD_ID, "animations/entity/rat.animation.json"); +public class RatEntityModel extends GeoModel { + private static final Identifier MODEL = RatsMischief.id("geo/entity/rat.geo.json"); + private static final Identifier ANIMATION = RatsMischief.id("animations/entity/rat.animation.json"); @Override public Identifier getModelResource(RatEntity rat) { @@ -29,32 +29,32 @@ public Identifier getAnimationResource(RatEntity rat) { } @Override - public void setCustomAnimations(RatEntity ratEntity, int instanceId, AnimationEvent animationEvent) { - super.setCustomAnimations(ratEntity, instanceId, animationEvent); + public void setCustomAnimations(RatEntity ratEntity, long instanceId, AnimationState animationState) { + super.setCustomAnimations(ratEntity, instanceId, animationState); - IBone head = this.getAnimationProcessor().getBone("head"); - IBone leftEar = this.getAnimationProcessor().getBone("leftear"); - IBone rightEar = this.getAnimationProcessor().getBone("rightear"); + CoreGeoBone head = this.getAnimationProcessor().getBone("head"); + CoreGeoBone leftEar = this.getAnimationProcessor().getBone("leftear"); + CoreGeoBone rightEar = this.getAnimationProcessor().getBone("rightear"); if (head != null && !ratEntity.isSniffing() && !ratEntity.isEating() && !ratEntity.isFlying()) { - head.setRotationX(MathHelper.clamp(-ratEntity.getPitch(), 0, 90) * ((float) Math.PI / 180F)); - leftEar.setRotationX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F)); - rightEar.setRotationX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F)); + head.setRotX(MathHelper.clamp(-ratEntity.getPitch(), 0, 90) * ((float) Math.PI / 180F)); + leftEar.setRotX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F)); + rightEar.setRotX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F)); // head.setRotationY(ratEntity.getHeadYaw() * ((float) Math.PI / 180F)); } // sexually aroused rat if (ratEntity.isAroused()) { - software.bernie.geckolib3.core.processor.IBone tail = this.getAnimationProcessor().getBone("tail"); - software.bernie.geckolib3.core.processor.IBone tailend = this.getAnimationProcessor().getBone("tailend"); + CoreGeoBone tail = this.getAnimationProcessor().getBone("tail"); + CoreGeoBone tailend = this.getAnimationProcessor().getBone("tailend"); - tail.setRotationX((float) (-45 * Math.PI / 180)); - tailend.setRotationX((float) (-30 * Math.PI / 180)); + tail.setRotX((float) (-45 * Math.PI / 180)); + tailend.setRotX((float) (-30 * Math.PI / 180)); } if (ratEntity.isBaby()) { - IBone root = this.getAnimationProcessor().getBone("root"); + CoreGeoBone root = this.getAnimationProcessor().getBone("root"); if (root != null) { root.setScaleX(0.5f); root.setScaleY(0.5f); diff --git a/src/main/java/ladysnake/ratsmischief/client/model/RatItemModel.java b/src/main/java/ladysnake/ratsmischief/client/model/RatItemModel.java index 693ff732..87c1da8f 100644 --- a/src/main/java/ladysnake/ratsmischief/client/model/RatItemModel.java +++ b/src/main/java/ladysnake/ratsmischief/client/model/RatItemModel.java @@ -3,12 +3,12 @@ import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.item.RatItem; import net.minecraft.util.Identifier; -import software.bernie.geckolib3.model.AnimatedGeoModel; +import software.bernie.geckolib.model.GeoModel; -public class RatItemModel extends AnimatedGeoModel { - private static final Identifier MODEL = new Identifier(RatsMischief.MOD_ID, "geo/item/rat.geo.json"); - private static final Identifier DEFAULT_TEXTURE = new Identifier(RatsMischief.MOD_ID, "textures/entity/wild.png"); - private static final Identifier ANIMATION = new Identifier(RatsMischief.MOD_ID, "animations/item/rat.animation.json"); +public class RatItemModel extends GeoModel { + private static final Identifier MODEL = RatsMischief.id("geo/item/rat.geo.json"); + private static final Identifier DEFAULT_TEXTURE = RatsMischief.id("textures/entity/wild.png"); + private static final Identifier ANIMATION = RatsMischief.id("animations/item/rat.animation.json"); @Override public Identifier getModelResource(RatItem rat) { diff --git a/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeEntityRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeEntityRenderer.java index da851720..53867ebb 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeEntityRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeEntityRenderer.java @@ -2,11 +2,11 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import net.minecraft.client.render.entity.EntityRendererFactory; -import software.bernie.geckolib3.model.AnimatedGeoModel; -import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer; +import software.bernie.geckolib.model.GeoModel; +import software.bernie.geckolib.renderer.GeoEntityRenderer; public class EnderEyeEntityRenderer extends GeoEntityRenderer { - protected EnderEyeEntityRenderer(EntityRendererFactory.Context ctx, AnimatedGeoModel modelProvider) { + protected EnderEyeEntityRenderer(EntityRendererFactory.Context ctx, GeoModel modelProvider) { super(ctx, modelProvider); } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeFeatureRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeFeatureRenderer.java index f80576d2..df5dcb50 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeFeatureRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/entity/EnderEyeFeatureRenderer.java @@ -1,36 +1,39 @@ package ladysnake.ratsmischief.client.render.entity; +import com.mojang.blaze3d.vertex.VertexConsumer; import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; -import software.bernie.geckolib3.renderers.geo.GeoLayerRenderer; -import software.bernie.geckolib3.renderers.geo.IGeoRenderer; +import software.bernie.geckolib.cache.object.BakedGeoModel; +import software.bernie.geckolib.renderer.GeoEntityRenderer; +import software.bernie.geckolib.renderer.layer.GeoRenderLayer; -public class EnderEyeFeatureRenderer extends GeoLayerRenderer { - public static final Identifier TEXTURE = new Identifier(RatsMischief.MOD_ID, "textures/entity/ender_eye.png"); +public class EnderEyeFeatureRenderer extends GeoRenderLayer { + public static final Identifier TEXTURE = RatsMischief.id("textures/entity/ender_eye.png"); private final EnderEyeEntityRenderer enderEyeEntityRenderer; - public EnderEyeFeatureRenderer(IGeoRenderer entityRendererIn, EnderEyeEntityRenderer enderEyeEntityRenderer) { + public EnderEyeFeatureRenderer(GeoEntityRenderer entityRendererIn, EnderEyeEntityRenderer enderEyeEntityRenderer) { super(entityRendererIn); this.enderEyeEntityRenderer = enderEyeEntityRenderer; } @Override - public void render(MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, int packedLightIn, RatEntity ratEntity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { + public void render(MatrixStack matrixStackIn, RatEntity ratEntity, BakedGeoModel bakedModel, RenderLayer renderType, VertexConsumerProvider bufferSourceIn, VertexConsumer bufferIn, float partialTicks, int packedLightIn, int packedOverlayIn) { if (ratEntity.isSpy() && !ratEntity.isInvisible()) { - this.enderEyeEntityRenderer.render(this.getEntityModel().getModel(this.getEntityModel().getModelResource(ratEntity)), + this.enderEyeEntityRenderer.defaultRender( + matrixStackIn, ratEntity, - partialTicks, + bufferSourceIn, RenderLayer.getEntityCutout(TEXTURE), - matrixStackIn, bufferIn, - bufferIn.getBuffer(RenderLayer.getEntityCutout(TEXTURE)), - packedLightIn, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); + 0.0F, + partialTicks, + packedLightIn + ); } } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatEntityRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatEntityRenderer.java index 118e2cee..0ec48308 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatEntityRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatEntityRenderer.java @@ -2,11 +2,11 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import net.minecraft.client.render.entity.EntityRendererFactory; -import software.bernie.geckolib3.model.AnimatedGeoModel; -import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer; +import software.bernie.geckolib.model.GeoModel; +import software.bernie.geckolib.renderer.GeoEntityRenderer; public class PartyHatEntityRenderer extends GeoEntityRenderer { - protected PartyHatEntityRenderer(EntityRendererFactory.Context ctx, AnimatedGeoModel modelProvider) { + protected PartyHatEntityRenderer(EntityRendererFactory.Context ctx, GeoModel modelProvider) { super(ctx, modelProvider); } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatFeatureRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatFeatureRenderer.java index 7fd9980f..c1daa846 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatFeatureRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/entity/PartyHatFeatureRenderer.java @@ -1,48 +1,51 @@ package ladysnake.ratsmischief.client.render.entity; import com.google.common.collect.Sets; +import com.mojang.blaze3d.vertex.VertexConsumer; import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.RatsMischiefUtils; import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; -import software.bernie.geckolib3.renderers.geo.GeoLayerRenderer; -import software.bernie.geckolib3.renderers.geo.IGeoRenderer; +import software.bernie.geckolib.cache.object.BakedGeoModel; +import software.bernie.geckolib.renderer.GeoRenderer; +import software.bernie.geckolib.renderer.layer.GeoRenderLayer; import java.util.Set; -public class PartyHatFeatureRenderer extends GeoLayerRenderer { +public class PartyHatFeatureRenderer extends GeoRenderLayer { public static final Set DISALLOWED_TYPES = Sets.immutableEnumSet(RatEntity.Type.RAT_KID, RatEntity.Type.BIGGIE_CHEESE, RatEntity.Type.REMY); public static Identifier[] TEXTURES; private final PartyHatEntityRenderer partyHatEntityRenderer; - public PartyHatFeatureRenderer(IGeoRenderer entityRendererIn, PartyHatEntityRenderer partyHatEntityRenderer) { + public PartyHatFeatureRenderer(GeoRenderer entityRendererIn, PartyHatEntityRenderer partyHatEntityRenderer) { super(entityRendererIn); this.partyHatEntityRenderer = partyHatEntityRenderer; } @Override - public void render(MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, int packedLightIn, RatEntity ratEntity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { + public void render(MatrixStack matrixStackIn, RatEntity ratEntity, BakedGeoModel bakedModel, RenderLayer renderType, VertexConsumerProvider bufferSourceIn, VertexConsumer bufferIn, float partialTicks, int packedLightIn, int packedOverlayIn) { if (RatsMischiefUtils.IS_BIRTHDAY && !DISALLOWED_TYPES.contains(ratEntity.getRatType())) { if (TEXTURES == null) { TEXTURES = new Identifier[RatEntity.PartyHat.values().length]; for (RatEntity.PartyHat hat : RatEntity.PartyHat.values()) { - TEXTURES[hat.ordinal()] = new Identifier(RatsMischief.MOD_ID, "textures/entity/birthday_hats/" + hat.toString().toLowerCase() + ".png"); + TEXTURES[hat.ordinal()] = RatsMischief.id("textures/entity/birthday_hats/" + hat.toString().toLowerCase() + ".png"); } } Identifier hatTexture = TEXTURES[ratEntity.getPartyHat().ordinal()]; - this.partyHatEntityRenderer.render(this.getEntityModel().getModel(this.getEntityModel().getModelResource(ratEntity)), + this.partyHatEntityRenderer.defaultRender( + matrixStackIn, ratEntity, - partialTicks, + bufferSourceIn, RenderLayer.getEntityCutout(hatTexture), - matrixStackIn, bufferIn, - bufferIn.getBuffer(RenderLayer.getEntityCutout(hatTexture)), - packedLightIn, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); + 0.0F, + partialTicks, + packedLightIn + ); } } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/entity/RatEntityRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/entity/RatEntityRenderer.java index b17aa750..52a6cce9 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/entity/RatEntityRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/entity/RatEntityRenderer.java @@ -7,18 +7,19 @@ import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.DyeColor; import net.minecraft.util.Identifier; +import net.minecraft.util.math.Axis; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Quaternion; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; -import software.bernie.geckolib3.geo.render.built.GeoBone; -import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer; +import org.joml.Quaternionf; +import software.bernie.geckolib.cache.object.BakedGeoModel; +import software.bernie.geckolib.cache.object.GeoBone; +import software.bernie.geckolib.renderer.GeoEntityRenderer; public class RatEntityRenderer extends GeoEntityRenderer { // variables needed for later @@ -29,8 +30,8 @@ public class RatEntityRenderer extends GeoEntityRenderer { public RatEntityRenderer(EntityRendererFactory.Context context) { super(context, new RatEntityModel()); this.shadowRadius = 0.35f; - this.addLayer(new PartyHatFeatureRenderer(this, new PartyHatEntityRenderer(context, new RatEntityModel()))); - this.addLayer(new EnderEyeFeatureRenderer(this, new EnderEyeEntityRenderer(context, new RatEntityModel()))); + this.addRenderLayer(new PartyHatFeatureRenderer(this, new PartyHatEntityRenderer(context, new RatEntityModel()))); + this.addRenderLayer(new EnderEyeFeatureRenderer(this, new EnderEyeEntityRenderer(context, new RatEntityModel()))); } @Override @@ -52,32 +53,31 @@ public void render(RatEntity ratEntity, float entityYaw, float partialTick, Matr } @Override - public void renderEarly(RatEntity ratEntity, MatrixStack stackIn, float ticks, VertexConsumerProvider vertexConsumerProvider, VertexConsumer vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks) { + public void preRender(MatrixStack poseStack, RatEntity ratEntity, BakedGeoModel model, VertexConsumerProvider vertexConsumerProvider, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { this.itemStack = ratEntity.isSitting() || ratEntity.isSneaking() ? ItemStack.EMPTY : ratEntity.getEquippedStack(EquipmentSlot.MAINHAND); this.vertexConsumerProvider = vertexConsumerProvider; this.ratTexture = this.getTexture(ratEntity); - super.renderEarly(ratEntity, stackIn, ticks, vertexConsumerProvider, vertexBuilder, packedLightIn, packedOverlayIn, red, - green, blue, partialTicks); + super.preRender(poseStack, ratEntity, model, vertexConsumerProvider, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); } @Override - public void renderRecursively(GeoBone bone, MatrixStack stack, VertexConsumer bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) { + public void renderRecursively(MatrixStack stack, RatEntity animatable, GeoBone bone, RenderLayer renderType, VertexConsumerProvider bufferSourceIn, VertexConsumer bufferIn, boolean isReRender, float partialTick, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) { if (bone.getName().equals("bodybone")) { stack.push(); - stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90)); - stack.translate(bone.getPositionX(), bone.getPositionZ(), bone.getPositionY() - 0.05); + stack.multiply(Axis.X_POSITIVE.rotationDegrees(-90)); + stack.translate(bone.getPosX(), bone.getPosZ(), bone.getPosY() - 0.05); stack.scale(0.7f, 0.7f, 0.7f); - stack.multiply(new Quaternion(bone.getRotationX(), bone.getRotationZ(), bone.getRotationY(), false)); + stack.multiply(new Quaternionf(bone.getRotX(), bone.getRotZ(), bone.getRotY(), 1.0F)); - MinecraftClient.getInstance().getItemRenderer().renderItem(this.itemStack, ModelTransformation.Mode.THIRD_PERSON_RIGHT_HAND, packedLightIn, packedOverlayIn, stack, this.vertexConsumerProvider, 0); + MinecraftClient.getInstance().getItemRenderer().renderItem(this.itemStack, ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, packedLightIn, packedOverlayIn, stack, this.vertexConsumerProvider, animatable.getWorld(), 0); stack.pop(); // restore the render buffer - GeckoLib expects this state otherwise you'll have weird texture issues bufferIn = this.vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.ratTexture)); } - super.renderRecursively(bone, stack, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha); + super.renderRecursively(stack, animatable, bone, renderType, bufferSourceIn, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, red, green, blue, alpha); } @Override @@ -90,7 +90,7 @@ protected int getBlockLight(RatEntity rat, BlockPos blockPos) { } @Override - public boolean shouldShowName(RatEntity animatable) { - return super.shouldShowName(animatable) && !animatable.isInvisible(); + public boolean hasLabel(RatEntity animatable) { + return super.hasLabel(animatable) && !animatable.isInvisible(); } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/item/RatItemRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/item/RatItemRenderer.java index 1ec63307..e1ecbd2e 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/item/RatItemRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/item/RatItemRenderer.java @@ -8,15 +8,14 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import ladysnake.ratsmischief.common.item.RatItem; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.util.DyeColor; import net.minecraft.util.Identifier; -import software.bernie.geckolib3.geo.render.built.GeoModel; -import software.bernie.geckolib3.renderers.geo.GeoItemRenderer; +import software.bernie.geckolib.renderer.GeoItemRenderer; public class RatItemRenderer extends GeoItemRenderer { private ThreadLocal currentTexture = new ThreadLocal<>(); @@ -26,10 +25,13 @@ public RatItemRenderer() { } @Override - public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvider bufferSource, int packedLight, ItemStack stack) { -// super.render(animatable, matrices, bufferSource, packedLight, stack); + public void render(ItemStack stack, ModelTransformationMode transformType, MatrixStack matrices, VertexConsumerProvider bufferSource, int packedLight, int packedOverlay) { +// super.render(stack, transformType, matrices, bufferSource, packedLight, packedOverlay); + + this.animatable = (RatItem) stack.getItem(); + this.currentItemStack = stack; + this.renderPerspective = transformType; - GeoModel model = this.modelProvider.getModel(this.modelProvider.getModelResource(animatable)); matrices.push(); matrices.translate(0.5f, 0.51f, 0.5f); @@ -52,7 +54,7 @@ public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvi MinecraftClient.getInstance().getTextureManager().bindTexture(ratTexture); RenderLayer renderLayer = RenderLayer.getEntityCutout(ratTexture); - this.render(model, animatable, 0.0F, renderLayer, matrices, bufferSource, bufferSource.getBuffer(renderLayer), packedLight, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); + this.defaultRender(matrices, this.animatable, bufferSource, renderLayer, bufferSource.getBuffer(renderLayer), 0, MinecraftClient.getInstance().getTickDelta(), packedLight); // ender eye if (stack.getNbt() != null @@ -61,7 +63,7 @@ public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvi && stack.getNbt().getCompound(RatsMischief.MOD_ID).getCompound("rat").contains("Spy") && stack.getNbt().getCompound(RatsMischief.MOD_ID).getCompound("rat").getBoolean("Spy")) { MinecraftClient.getInstance().getTextureManager().bindTexture(EnderEyeFeatureRenderer.TEXTURE); - this.render(model, animatable, 0.0F, RenderLayer.getEntityCutout(EnderEyeFeatureRenderer.TEXTURE), matrices, bufferSource, null, packedLight, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); + this.defaultRender(matrices, this.animatable, bufferSource, RenderLayer.getEntityCutout(EnderEyeFeatureRenderer.TEXTURE), bufferSource.getBuffer(renderLayer), 0, MinecraftClient.getInstance().getTickDelta(), packedLight); } // party hat @@ -74,7 +76,7 @@ public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvi Identifier hatTexture = PartyHatFeatureRenderer.TEXTURES[RatEntity.PartyHat.valueOf(hat).ordinal()]; MinecraftClient.getInstance().getTextureManager().bindTexture(hatTexture); - this.render(model, animatable, 0.0F, RenderLayer.getEntityCutout(hatTexture), matrices, bufferSource, null, packedLight, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); + this.defaultRender(matrices, this.animatable, bufferSource, RenderLayer.getEntityCutout(hatTexture), bufferSource.getBuffer(renderLayer), 0, MinecraftClient.getInstance().getTickDelta(), packedLight); } } @@ -86,9 +88,4 @@ public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvi public Identifier getTextureLocation(RatItem instance) { return currentTexture.get() != null ? currentTexture.get() : super.getTextureLocation(instance); } - - @Override - public Identifier getTextureResource(RatItem entity) { - return currentTexture.get() != null ? currentTexture.get() : super.getTextureResource(entity); - } } diff --git a/src/main/java/ladysnake/ratsmischief/client/render/item/RatMasterMaskItemRenderer.java b/src/main/java/ladysnake/ratsmischief/client/render/item/RatMasterMaskItemRenderer.java index 22d0a095..c2af5498 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/item/RatMasterMaskItemRenderer.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/item/RatMasterMaskItemRenderer.java @@ -1,12 +1,11 @@ package ladysnake.ratsmischief.client.render.item; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; -import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; @@ -14,11 +13,13 @@ import net.minecraft.util.Identifier; import net.minecraft.util.Unit; import net.minecraft.util.profiler.Profiler; +import org.jetbrains.annotations.NotNull; +import org.quiltmc.qsl.resource.loader.api.reloader.IdentifiableResourceReloader; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -public class RatMasterMaskItemRenderer implements BuiltinItemRendererRegistry.DynamicItemRenderer, IdentifiableResourceReloadListener { +public class RatMasterMaskItemRenderer implements BuiltinItemRendererRegistry.DynamicItemRenderer, IdentifiableResourceReloader { private final Identifier rendererId; private final Identifier itemId; private ItemRenderer itemRenderer; @@ -26,12 +27,12 @@ public class RatMasterMaskItemRenderer implements BuiltinItemRendererRegistry.Dy private BakedModel wornModel; public RatMasterMaskItemRenderer(Identifier itemId) { - this.rendererId = new Identifier(itemId.getNamespace(), itemId.getPath() + "_renderer"); + this.rendererId = Identifier.tryParse(itemId + "_renderer"); this.itemId = itemId; } @Override - public Identifier getFabricId() { + public @NotNull Identifier getQuiltId() { return this.rendererId; } @@ -43,17 +44,17 @@ public CompletableFuture reload(Synchronizer synchronizer, ResourceManager final MinecraftClient client = MinecraftClient.getInstance(); this.itemRenderer = client.getItemRenderer(); this.inventoryModel = client.getBakedModelManager().getModel(new ModelIdentifier(this.itemId, "inventory")); - this.wornModel = client.getBakedModelManager().getModel(new ModelIdentifier(this.itemId + "_worn", "inventory")); + this.wornModel = client.getBakedModelManager().getModel(new ModelIdentifier(new Identifier(this.itemId.getNamespace(), this.itemId.getPath() + "_worn"), "inventory")); applyProfiler.pop(); applyProfiler.endTick(); }, applyExecutor); } @Override - public void render(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + public void render(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { matrices.pop(); matrices.push(); - if (mode == ModelTransformation.Mode.GUI || mode == ModelTransformation.Mode.GROUND || mode == ModelTransformation.Mode.FIXED) { + if (mode == ModelTransformationMode.GUI || mode == ModelTransformationMode.GROUND || mode == ModelTransformationMode.FIXED) { this.itemRenderer.renderItem(stack, mode, false, matrices, vertexConsumers, light, overlay, this.inventoryModel); } else { boolean leftHanded; diff --git a/src/main/java/ladysnake/ratsmischief/client/render/item/recipe/SpyRatCraftingRecipe.java b/src/main/java/ladysnake/ratsmischief/client/render/item/recipe/SpyRatCraftingRecipe.java index 43c1dfbf..151fc63d 100644 --- a/src/main/java/ladysnake/ratsmischief/client/render/item/recipe/SpyRatCraftingRecipe.java +++ b/src/main/java/ladysnake/ratsmischief/client/render/item/recipe/SpyRatCraftingRecipe.java @@ -3,12 +3,14 @@ import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.init.ModItems; import ladysnake.ratsmischief.common.item.RatItem; -import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.RecipeInputInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.recipe.CraftingCategory; import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.SpecialCraftingRecipe; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.util.Identifier; import net.minecraft.world.World; @@ -17,8 +19,8 @@ public class SpyRatCraftingRecipe extends SpecialCraftingRecipe { private static final Ingredient RABBIT_HIDE = Ingredient.ofItems(Items.RABBIT_HIDE); private static final Ingredient ENDER_EYE = Ingredient.ofItems(Items.ENDER_EYE); - public SpyRatCraftingRecipe(Identifier id) { - super(id); + public SpyRatCraftingRecipe(Identifier id, CraftingCategory craftingCategory) { + super(id, CraftingCategory.MISC); } @Override @@ -27,7 +29,7 @@ public boolean isIgnoredInRecipeBook() { } @Override - public boolean matches(CraftingInventory inventory, World world) { + public boolean matches(RecipeInputInventory inventory, World world) { for (int i = 0; i < 3; ++i) { ItemStack itemStack = inventory.getStack(i); if (!itemStack.isEmpty()) { @@ -41,13 +43,13 @@ public boolean matches(CraftingInventory inventory, World world) { } @Override - public ItemStack craft(CraftingInventory inventory) { + public ItemStack craft(RecipeInputInventory inventory, DynamicRegistryManager registryManager) { ItemStack spyRatStack = ItemStack.EMPTY; for (int i = 6; i < 9; ++i) { ItemStack ratStack = inventory.getStack(i); if (!ratStack.isEmpty()) { - if (ratStack.getItem() instanceof RatItem + if (ratStack.isOf(ModItems.RAT) && ratStack.getNbt() != null && ratStack.getNbt().contains(RatsMischief.MOD_ID) && ratStack.getNbt().getCompound(RatsMischief.MOD_ID).contains("rat") @@ -66,7 +68,7 @@ public ItemStack craft(CraftingInventory inventory) { } @Override - public ItemStack getOutput() { + public ItemStack getResult(DynamicRegistryManager registryManager) { return new ItemStack(ModItems.RAT); } diff --git a/src/main/java/ladysnake/ratsmischief/common/RatsMischief.java b/src/main/java/ladysnake/ratsmischief/common/RatsMischief.java index 6e32e072..4a9b454f 100644 --- a/src/main/java/ladysnake/ratsmischief/common/RatsMischief.java +++ b/src/main/java/ladysnake/ratsmischief/common/RatsMischief.java @@ -1,34 +1,32 @@ package ladysnake.ratsmischief.common; import ladysnake.ratsmischief.client.render.item.recipe.SpyRatCraftingRecipe; -import ladysnake.ratsmischief.common.init.*; +import ladysnake.ratsmischief.common.init.ModBlocks; +import ladysnake.ratsmischief.common.init.ModEnchantments; +import ladysnake.ratsmischief.common.init.ModEntities; +import ladysnake.ratsmischief.common.init.ModItems; +import ladysnake.ratsmischief.common.init.ModLootTables; +import ladysnake.ratsmischief.common.init.ModSoundEvents; +import ladysnake.ratsmischief.common.init.ModStatusEffects; +import ladysnake.ratsmischief.common.init.ModTags; import ladysnake.ratsmischief.common.world.RatSpawner; -import net.fabricmc.fabric.api.loot.v2.LootTableEvents; -import net.minecraft.enchantment.EnchantmentLevelEntry; +import ladysnake.ratsmischief.mialeemisc.MialeeMisc; import net.minecraft.entity.decoration.painting.PaintingVariant; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.loot.LootPool; -import net.minecraft.loot.condition.RandomChanceLootCondition; -import net.minecraft.loot.entry.ItemEntry; -import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.SpecialRecipeSerializer; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import net.minecraft.world.Difficulty; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.lifecycle.api.event.ServerWorldTickEvents; -import software.bernie.geckolib3.GeckoLib; public class RatsMischief implements ModInitializer { public static final String MOD_ID = "ratsmischief"; public static final SpecialRecipeSerializer SPY_RAT_RECIPE = RecipeSerializer.register( "ratsmischief:crafting_special_spy_rat", new SpecialRecipeSerializer<>(SpyRatCraftingRecipe::new) ); - public static final Identifier ANCIENT_CITY_CHESTS = new Identifier("minecraft", "chests/ancient_city"); public static Identifier id(String path) { return new Identifier(MOD_ID, path); @@ -36,17 +34,16 @@ public static Identifier id(String path) { @Override public void onInitialize(ModContainer mod) { - GeckoLib.initialize(); - // initializing stuff ModEntities.initialize(); ModBlocks.initialize(); // ModItemGroup.initialize(); ModItems.initialize(); - ModSoundEvents.initialize(); ModEnchantments.initialize(); ModLootTables.initialize(); + ModSoundEvents.initialize(); ModStatusEffects.initialize(); + ModTags.initialize(); // custom rat spawner in abandoned villages RatSpawner ratSpawner = new RatSpawner(); @@ -56,29 +53,8 @@ public void onInitialize(ModContainer mod) { }); // rat kid painting - Registry.register(Registry.PAINTING_VARIANT, new Identifier(MOD_ID, "a_rat_in_time"), new PaintingVariant(64, 48)); + Registry.register(Registries.PAINTING_VARIANT, RatsMischief.id("a_rat_in_time"), new PaintingVariant(64, 48)); - // clothed ingots and rat curse books spawning in ancient city chests - UniformLootNumberProvider lootTableRange = UniformLootNumberProvider.create(1, 1); - LootTableEvents.MODIFY.register((resourceManager, lootManager, id, supplier, setter) -> { - if (ANCIENT_CITY_CHESTS.equals(id)) { - { // clothed ingot - LootPool lootPool = LootPool.builder() - .rolls(lootTableRange) - .conditionally(RandomChanceLootCondition.builder(0.3f).build()) - .with(ItemEntry.builder(ModItems.CLOTHED_INGOT).build()).build(); - supplier.pool(lootPool); - } - { // rat curse book - ItemStack book = new ItemStack(Items.ENCHANTED_BOOK); - EnchantedBookItem.addEnchantment(book, new EnchantmentLevelEntry(ModEnchantments.RAT_CURSE, 1)); - LootPool lootPool = LootPool.builder() - .rolls(lootTableRange) - .conditionally(RandomChanceLootCondition.builder(0.3f).build()) - .with(ItemEntry.builder(ModItems.CLOTHED_INGOT).build()).build(); - supplier.pool(lootPool); - } - } - }); + MialeeMisc.onInitialize(); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/RatsMischiefUtils.java b/src/main/java/ladysnake/ratsmischief/common/RatsMischiefUtils.java index 6a0f976d..1acee1e4 100644 --- a/src/main/java/ladysnake/ratsmischief/common/RatsMischiefUtils.java +++ b/src/main/java/ladysnake/ratsmischief/common/RatsMischiefUtils.java @@ -13,7 +13,7 @@ public class RatsMischiefUtils { // DATES public static final boolean IS_WORLD_RAT_DAY = DateTimeFormatter.ofPattern("dd/MM").format(LocalDateTime.now()).equals("04/04"); // RENDER - public static final Identifier REMY_TEXTURE = new Identifier(RatsMischief.MOD_ID, "textures/entity/named/remy.png"); + public static final Identifier REMY_TEXTURE = RatsMischief.id("textures/entity/named/remy.png"); private static final LocalDate today = LocalDate.now(); public static final boolean IS_RAT_BIRTHDAY = LocalDate.of(today.getYear(), 7, 19).compareTo(today) * today.compareTo(LocalDate.of(today.getYear(), 7, 25)) >= 0; public static final boolean IS_MISCHIEF_BIRTHDAY = (LocalDate.of(today.getYear(), 12, 28).compareTo(today) * today.compareTo(LocalDate.of(today.getYear(), 12, 31)) >= 0) @@ -26,7 +26,7 @@ public static Identifier getRatTexture(RatEntity.Type ratType, DyeColor ratColor if (RAT_KID_TEXTURES == null) { RAT_KID_TEXTURES = new Identifier[16]; for (DyeColor color : DyeColor.values()) { - RAT_KID_TEXTURES[color.getId()] = new Identifier(RatsMischief.MOD_ID, "textures/entity/rat_kid/rat_kid_" + color.getName().toLowerCase(Locale.ROOT) + ".png"); + RAT_KID_TEXTURES[color.getId()] = RatsMischief.id("textures/entity/rat_kid/rat_kid_" + color.getName().toLowerCase(Locale.ROOT) + ".png"); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseCooldownStatusEffect.java b/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseCooldownStatusEffect.java new file mode 100644 index 00000000..620b5260 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseCooldownStatusEffect.java @@ -0,0 +1,10 @@ +package ladysnake.ratsmischief.common.effect; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectType; + +public class RatCurseCooldownStatusEffect extends StatusEffect { + public RatCurseCooldownStatusEffect(StatusEffectType type, int color) { + super(type, color); + } +} diff --git a/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseStatusEffect.java b/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseStatusEffect.java index b834705f..c5a67c3d 100644 --- a/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseStatusEffect.java +++ b/src/main/java/ladysnake/ratsmischief/common/effect/RatCurseStatusEffect.java @@ -1,9 +1,6 @@ package ladysnake.ratsmischief.common.effect; import ladysnake.ratsmischief.common.init.ModStatusEffects; -import ladysnake.ratsmischief.common.requiem.RatsMischiefRequiemPlugin; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import ladysnake.requiem.common.remnant.RemnantTypes; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.AttributeContainer; import net.minecraft.entity.effect.StatusEffect; @@ -26,12 +23,12 @@ public void onApplied(LivingEntity entity, AttributeContainer attributes, int am if (entity instanceof PlayerEntity player) { for (int i = 0; i < 5; i++) { - ((ServerWorld) player.world).spawnParticles(ParticleTypes.LARGE_SMOKE, player.getX(), player.getY() + player.getHeight() / 2f, player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); - ((ServerWorld) player.world).spawnParticles(ParticleTypes.SMOKE, player.getX(), player.getY(), player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); + ((ServerWorld) player.getWorld()).spawnParticles(ParticleTypes.LARGE_SMOKE, player.getX(), player.getY() + player.getHeight() / 2f, player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); + ((ServerWorld) player.getWorld()).spawnParticles(ParticleTypes.SMOKE, player.getX(), player.getY(), player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); } player.playSound(SoundEvents.ENTITY_ILLUSIONER_MIRROR_MOVE, SoundCategory.PLAYERS, 1.0f, 1.0f); - RemnantComponent.get(player).become(RatsMischiefRequiemPlugin.RATIFIED_REMNANT_TYPE); + //RemnantComponent.get(player).become(RatsMischiefRequiemPlugin.RATIFIED_REMNANT_TYPE); } } @@ -41,13 +38,13 @@ public void onRemoved(LivingEntity entity, AttributeContainer attributes, int am if (entity instanceof PlayerEntity player) { for (int i = 0; i < 5; i++) { - ((ServerWorld) player.world).spawnParticles(ParticleTypes.LARGE_SMOKE, player.getX(), player.getY() + player.getHeight() / 2f, player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); - ((ServerWorld) player.world).spawnParticles(ParticleTypes.SMOKE, player.getX(), player.getY(), player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); + ((ServerWorld) player.getWorld()).spawnParticles(ParticleTypes.LARGE_SMOKE, player.getX(), player.getY() + player.getHeight() / 2f, player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); + ((ServerWorld) player.getWorld()).spawnParticles(ParticleTypes.SMOKE, player.getX(), player.getY(), player.getZ(), 100, 0.5f, 1f, 0.5f, 0.01f); } player.playSound(SoundEvents.ENTITY_ILLUSIONER_CAST_SPELL, SoundCategory.PLAYERS, 1.0f, 1.0f); player.addStatusEffect(new StatusEffectInstance(ModStatusEffects.RAT_CURSE_COOLDOWN, 1200, 0, false, false, true)); - RemnantComponent.get(player).become(RemnantTypes.MORTAL); + //RemnantComponent.get(player).become(RemnantTypes.MORTAL); } } } diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/RatEntity.java b/src/main/java/ladysnake/ratsmischief/common/entity/RatEntity.java index 8497b384..d0c814bc 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/RatEntity.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/RatEntity.java @@ -8,25 +8,44 @@ import ladysnake.ratsmischief.common.entity.ai.EatToHealGoal; import ladysnake.ratsmischief.common.entity.ai.FollowOwnerRatGoal; import ladysnake.ratsmischief.common.entity.ai.RatMeleeAttackGoal; -import ladysnake.ratsmischief.common.init.ModDamageSources; +import ladysnake.ratsmischief.common.init.ModDamageTypes; import ladysnake.ratsmischief.common.init.ModEntities; import ladysnake.ratsmischief.common.init.ModItems; import ladysnake.ratsmischief.common.init.ModSoundEvents; +import ladysnake.ratsmischief.common.init.ModTags; import ladysnake.ratsmischief.common.item.RatMasterArmorItem; -import ladysnake.ratsmischief.common.item.RatMasterOcarinaItem; -import ladysnake.ratsmischief.common.item.RatPouchItem; import ladysnake.ratsmischief.common.util.PlayerRatOwner; +import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.EndGatewayBlockEntity; -import net.minecraft.entity.*; -import net.minecraft.entity.ai.goal.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityData; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; +import net.minecraft.entity.ai.goal.AnimalMateGoal; +import net.minecraft.entity.ai.goal.AttackWithOwnerGoal; +import net.minecraft.entity.ai.goal.FollowOwnerGoal; +import net.minecraft.entity.ai.goal.Goal; +import net.minecraft.entity.ai.goal.LookAroundGoal; +import net.minecraft.entity.ai.goal.LookAtEntityGoal; +import net.minecraft.entity.ai.goal.PounceAtTargetGoal; +import net.minecraft.entity.ai.goal.RevengeGoal; +import net.minecraft.entity.ai.goal.SitGoal; +import net.minecraft.entity.ai.goal.SwimGoal; +import net.minecraft.entity.ai.goal.TargetGoal; +import net.minecraft.entity.ai.goal.TrackOwnerAttackerGoal; +import net.minecraft.entity.ai.goal.UniversalAngerGoal; +import net.minecraft.entity.ai.goal.WanderAroundFarGoal; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.damage.EntityDamageSource; +import net.minecraft.entity.damage.DamageTypes; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -50,38 +69,48 @@ import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.particle.ParticleTypes; +import net.minecraft.registry.Registries; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.SoundEvent; -import net.minecraft.util.*; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DyeColor; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.TimeHelper; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.intprovider.UniformIntProvider; +import net.minecraft.util.math.int_provider.UniformIntProvider; import net.minecraft.util.random.RandomGenerator; -import net.minecraft.util.registry.Registry; +import net.minecraft.world.EntityView; import net.minecraft.world.LocalDifficulty; import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; -import software.bernie.geckolib3.core.IAnimatable; -import software.bernie.geckolib3.core.PlayState; -import software.bernie.geckolib3.core.builder.AnimationBuilder; -import software.bernie.geckolib3.core.builder.ILoopType; -import software.bernie.geckolib3.core.controller.AnimationController; -import software.bernie.geckolib3.core.event.predicate.AnimationEvent; -import software.bernie.geckolib3.core.manager.AnimationData; -import software.bernie.geckolib3.core.manager.AnimationFactory; -import software.bernie.geckolib3.util.GeckoLibUtil; - -import java.util.*; +import software.bernie.geckolib.animatable.GeoEntity; +import software.bernie.geckolib.core.animatable.GeoAnimatable; +import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; +import software.bernie.geckolib.core.animation.AnimatableManager; +import software.bernie.geckolib.core.animation.Animation; +import software.bernie.geckolib.core.animation.AnimationController; +import software.bernie.geckolib.core.animation.AnimationState; +import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.object.PlayState; +import software.bernie.geckolib.util.GeckoLibUtil; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Locale; +import java.util.UUID; import java.util.function.Predicate; -public class RatEntity extends TameableEntity implements IAnimatable, Angerable { +public class RatEntity extends TameableEntity implements GeoEntity, Angerable { public static final Predicate PICKABLE_DROP_FILTER = (itemEntity) -> !itemEntity.cannotPickup() && itemEntity.isAlive(); public static final List NATURAL_TYPES = ImmutableList.of(Type.ALBINO, Type.BLACK, Type.GREY, Type.HUSKY, Type.LIGHT_BROWN, Type.BLUE); private static final List PARTY_HATS = List.of(PartyHat.values()); @@ -99,7 +128,14 @@ public class RatEntity extends TameableEntity implements IAnimatable, Angerable private static final TrackedData ATTACK_RIDING_TIME = DataTracker.registerData(RatEntity.class, TrackedDataHandlerRegistry.INTEGER); private static final TrackedData POTION_GENE = DataTracker.registerData(RatEntity.class, TrackedDataHandlerRegistry.INTEGER); private static final TrackedData SLOT = DataTracker.registerData(RatEntity.class, TrackedDataHandlerRegistry.INTEGER); - private final AnimationFactory factory = GeckoLibUtil.createFactory(this); + private static final RawAnimation ANIM_SITTING = RawAnimation.begin().then("animation.rat.flat", Animation.LoopType.LOOP); + private static final RawAnimation ANIM_EATING = RawAnimation.begin().then("animation.rat.eat", Animation.LoopType.LOOP); + private static final RawAnimation ANIM_FLYING = RawAnimation.begin().then("animation.rat.fly", Animation.LoopType.LOOP); + private static final RawAnimation ANIM_SNIFFING = RawAnimation.begin().then("animation.rat.sniff", Animation.LoopType.PLAY_ONCE); + private static final RawAnimation ANIM_DANCING = RawAnimation.begin().then("animation.rat.smug_dance", Animation.LoopType.LOOP); + private static final RawAnimation ANIM_RUNNING = RawAnimation.begin().then("animation.rat.run", Animation.LoopType.LOOP); + private static final RawAnimation ANIM_RUNNING_JERMA = RawAnimation.begin().then("animation.rat.jermarun", Animation.LoopType.LOOP); + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public Goal action; public int actionTimer = 0; private UUID targetUuid; @@ -111,7 +147,7 @@ public RatEntity(EntityType type, World worldIn) { } public static DefaultAttributeContainer.Builder createRatAttributes() { - return MobEntity.createMobAttributes().add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK, 0.0D).add(StepHeightEntityAttributeMain.STEP_HEIGHT, 2.0D).add(EntityAttributes.GENERIC_MAX_HEALTH, 8.0D).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5D).add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 0.1).add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32); + return MobEntity.createAttributes().add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK, 0.0D).add(StepHeightEntityAttributeMain.STEP_HEIGHT, 2.0D).add(EntityAttributes.GENERIC_MAX_HEALTH, 8.0D).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5D).add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 0.1).add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32); } public static Type getRandomNaturalType(RandomGenerator random) { @@ -204,32 +240,32 @@ protected void initGoals() { this.targetSelector.add(8, new UniversalAngerGoal<>(this, true)); } - private PlayState predicate(AnimationEvent event) { + private PlayState predicate(AnimationState event) { if (this.isFlying()) { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.fly", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_FLYING); return PlayState.CONTINUE; } else if (this.isEating()) { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.eat", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_EATING); return PlayState.CONTINUE; } else if (this.isSitting() || this.isSneaking()) { this.setSniffing(false); this.setEating(false); - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.flat", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_SITTING); return PlayState.CONTINUE; } else if (event.isMoving()) { this.setSniffing(false); this.setEating(false); if (this.getRatType() == Type.JERMA) { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.jermarun", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_RUNNING_JERMA); } else { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.run", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_RUNNING); } return PlayState.CONTINUE; } else if (this.isSniffing()) { if (this.getRatType() == Type.RAT_KID || RatsMischiefUtils.IS_WORLD_RAT_DAY || RatsMischiefUtils.IS_BIRTHDAY) { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.smug_dance", ILoopType.EDefaultLoopTypes.LOOP)); + event.getController().setAnimation(ANIM_DANCING); } else { - event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.rat.sniff", ILoopType.EDefaultLoopTypes.PLAY_ONCE)); + event.getController().setAnimation(ANIM_SNIFFING); } return PlayState.CONTINUE; } @@ -238,13 +274,13 @@ private PlayState predicate(AnimationEvent event) { } @Override - public void registerControllers(AnimationData data) { - data.addAnimationController(new AnimationController<>(this, "controller", 0, this::predicate)); + public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { + controllers.add(new AnimationController<>(this, "controller", this::predicate)); } @Override - public AnimationFactory getFactory() { - return this.factory; + public AnimatableInstanceCache getAnimatableInstanceCache() { + return this.cache; } @Override @@ -318,11 +354,11 @@ public StatusEffect getPotionGene() { if (this.dataTracker.get(POTION_GENE) == -1) { return null; } - return Registry.STATUS_EFFECT.get(this.dataTracker.get(POTION_GENE)); + return Registries.STATUS_EFFECT.get(this.dataTracker.get(POTION_GENE)); } public void setPotionGene(StatusEffect potion) { - this.dataTracker.set(POTION_GENE, Registry.STATUS_EFFECT.getRawId(potion)); + this.dataTracker.set(POTION_GENE, Registries.STATUS_EFFECT.getRawId(potion)); } public int getSlot() { @@ -340,7 +376,7 @@ public void readCustomDataFromNbt(NbtCompound tag) { if (tag.contains("RatType")) { this.setRatType(Type.valueOf(tag.getString("RatType"))); } - this.readAngerFromNbt(this.world, tag); + this.readAngerFromNbt(this.getWorld(), tag); if (tag.contains("Sitting")) { this.setSitting(tag.getBoolean("Sitting")); @@ -379,9 +415,9 @@ public void readCustomDataFromNbt(NbtCompound tag) { } if (tag.contains("PotionGene")) { - Identifier id = new Identifier(tag.getString("PotionGene")); - StatusEffect potion = Registry.STATUS_EFFECT.get(id); - this.dataTracker.set(POTION_GENE, Registry.STATUS_EFFECT.getRawId(potion)); + Identifier id = Identifier.tryParse(tag.getString("PotionGene")); + StatusEffect potion = Registries.STATUS_EFFECT.get(id); + this.dataTracker.set(POTION_GENE, Registries.STATUS_EFFECT.getRawId(potion)); } } @@ -402,15 +438,10 @@ public void writeCustomDataToNbt(NbtCompound tag) { tag.putInt("AttackRidingTime", this.getAttackRidingTime()); tag.putInt("Slot", this.getSlot()); if (this.getPotionGene() != null) { - tag.putString("PotionGene", String.valueOf(Registry.STATUS_EFFECT.getId(this.getPotionGene()))); + tag.putString("PotionGene", String.valueOf(Registries.STATUS_EFFECT.getId(this.getPotionGene()))); } } - @Override - public boolean canMoveVoluntarily() { - return super.canMoveVoluntarily(); - } - @Override public void setYaw(float yaw) { if (!this.isFlying()) { @@ -445,7 +476,7 @@ public void tick() { } // sexually aroused rat - if (!this.world.isClient) { + if (!this.getWorld().isClient) { this.setAroused(this.getLoveTicks() > 0); } @@ -475,14 +506,14 @@ public void tick() { boolean bl = false; if (hitResult.getType() == HitResult.Type.BLOCK) { BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos(); - BlockState blockState = this.world.getBlockState(blockPos); + BlockState blockState = this.getWorld().getBlockState(blockPos); if (blockState.isOf(Blocks.NETHER_PORTAL)) { this.setInNetherPortal(blockPos); bl = true; } else if (blockState.isOf(Blocks.END_GATEWAY)) { - BlockEntity blockEntity = this.world.getBlockEntity(blockPos); + BlockEntity blockEntity = this.getWorld().getBlockEntity(blockPos); if (blockEntity instanceof EndGatewayBlockEntity && EndGatewayBlockEntity.canTeleport(this)) { - EndGatewayBlockEntity.tryTeleportingEntity(this.world, blockPos, blockState, this, (EndGatewayBlockEntity) blockEntity); + EndGatewayBlockEntity.tryTeleportingEntity(this.getWorld(), blockPos, blockState, this, (EndGatewayBlockEntity) blockEntity); } bl = true; @@ -501,7 +532,7 @@ public void tick() { // this.updateRotation(); if (this.isTouchingWater()) { for (int i = 0; i < 4; ++i) { - this.world.addParticle(ParticleTypes.BUBBLE, d - vec3d.x * 0.25, e - vec3d.y * 0.25, f - vec3d.z * 0.25, vec3d.x, vec3d.y, vec3d.z); + this.getWorld().addParticle(ParticleTypes.BUBBLE, d - vec3d.x * 0.25, e - vec3d.y * 0.25, f - vec3d.z * 0.25, vec3d.x, vec3d.y, vec3d.z); } } } @@ -626,26 +657,26 @@ public void tickMovement() { this.setMovementSpeed(0.5f); } - if (!this.world.isClient && this.canPickUpLoot() && this.isAlive() && !this.dead && !this.isEating()) { - for (ItemEntity itemEntity : this.world.getNonSpectatingEntities(ItemEntity.class, this.getBoundingBox().expand(1, 0, 1))) { + if (!this.getWorld().isClient && this.canPickUpLoot() && this.isAlive() && !this.dead && !this.isEating()) { + for (ItemEntity itemEntity : this.getWorld().getNonSpectatingEntities(ItemEntity.class, this.getBoundingBox().expand(1, 0, 1))) { if (!itemEntity.isRemoved() && !itemEntity.getStack().isEmpty() && !itemEntity.cannotPickup() && this.canGather(itemEntity.getStack())) { this.loot(itemEntity); } } } - if (!this.world.isClient) { - this.tickAngerLogic((ServerWorld) this.world, true); + if (!this.getWorld().isClient) { + this.tickAngerLogic((ServerWorld) this.getWorld(), true); } - if (this.world.isClient) { + if (this.getWorld().isClient) { if (this.getPotionGene() != null) { StatusEffect effect = this.getPotionGene(); int k = effect.getColor(); double d = (float) ((k >> 16 & 0xFF)) / 255.0F; double e = (float) ((k >> 8 & 0xFF)) / 255.0F; double f = (float) ((k & 0xFF)) / 255.0F; - this.world.addParticle(ParticleTypes.ENTITY_EFFECT, this.getParticleX(0.5), this.getRandomBodyY(), this.getParticleZ(0.5), d, e, f); + this.getWorld().addParticle(ParticleTypes.ENTITY_EFFECT, this.getParticleX(0.5), this.getRandomBodyY(), this.getParticleZ(0.5), d, e, f); } } } @@ -661,7 +692,7 @@ public void pushAwayFrom(Entity entity) { public ActionResult interactMob(PlayerEntity player, Hand hand) { ItemStack itemStack = player.getStackInHand(hand); Item item = itemStack.getItem(); - if (this.world.isClient) { + if (this.getWorld().isClient) { boolean bl = this.isOwner(player) || this.isTamed() && !this.isTamed() && !this.hasAngerTime(); return bl ? ActionResult.CONSUME : ActionResult.PASS; } else { @@ -695,7 +726,7 @@ public ActionResult interactMob(PlayerEntity player, Hand hand) { } // sitting - if (!(item instanceof RatPouchItem) && !(item instanceof RatMasterOcarinaItem) && (!this.isBreedingItem(itemStack)) && !(itemStack.getItem() instanceof DyeItem && this.getRatType() == Type.RAT_KID)) { + if (!(itemStack.isIn(ModTags.RAT_POUCHES)) && !(itemStack.isOf(ModItems.RAT_MASTER_OCARINA)) && (!this.isBreedingItem(itemStack)) && !(itemStack.getItem() instanceof DyeItem && this.getRatType() == Type.RAT_KID)) { this.setSitting(!this.isSitting()); return ActionResult.SUCCESS; } @@ -707,13 +738,13 @@ public ActionResult interactMob(PlayerEntity player, Hand hand) { this.setOwner(player); this.navigation.stop(); this.setTarget(null); - this.world.sendEntityStatus(this, (byte) 7); + this.getWorld().sendEntityStatus(this, (byte) 7); } else { for (int i = 0; i < 7; ++i) { double d = this.random.nextGaussian() * 0.02D; double e = this.random.nextGaussian() * 0.02D; double f = this.random.nextGaussian() * 0.02D; - ((ServerWorld) this.world).spawnParticles(ParticleTypes.SMOKE, this.getParticleX(1.0D), this.getRandomBodyY() + 0.5D, this.getParticleZ(1.0D), 1, d, e, f, 0f); + ((ServerWorld) this.getWorld()).spawnParticles(ParticleTypes.SMOKE, this.getParticleX(1.0D), this.getRandomBodyY() + 0.5D, this.getParticleZ(1.0D), 1, d, e, f, 0f); } } @@ -812,12 +843,12 @@ public boolean canAttackWithOwner(LivingEntity target, LivingEntity owner) { if (!(target instanceof CreeperEntity || (target instanceof GhastEntity))) { if (target instanceof RatEntity rat) { return !rat.isTamed() || rat.getOwner() != owner; - } else if (target instanceof PlayerEntity && owner instanceof PlayerEntity && !((PlayerEntity) owner).shouldDamagePlayer((PlayerEntity) target)) { + } else if (target instanceof PlayerEntity targetPlayer && owner instanceof PlayerEntity ownerPlayer && !ownerPlayer.shouldDamagePlayer(targetPlayer)) { return false; - } else if (target instanceof HorseEntity && ((HorseEntity) target).isTame()) { + } else if (target instanceof HorseEntity horse && horse.isTame()) { return false; } else { - return !(target instanceof TameableEntity) || !((TameableEntity) target).isTamed(); + return !(target instanceof TameableEntity tameable) || !(tameable.isTamed()); } } else { return false; @@ -834,7 +865,7 @@ public boolean tryAttack(Entity target) { float damage = (float) this.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE); damage *= RatMasterArmorItem.getDamageMultiplier(this.getOwner()); target.timeUntilRegen = 0; - if (target.damage(ModDamageSources.ratDamage(this), damage)) { + if (target.damage(ModDamageTypes.ratDamage(this), damage)) { if (this.getPotionGene() != null && target instanceof LivingEntity livingEntity) { livingEntity.addStatusEffect(new StatusEffectInstance(this.getPotionGene(), 5 * 20)); } @@ -893,12 +924,10 @@ public boolean damage(DamageSource source, float amount) { @Override public boolean isInvulnerableTo(DamageSource damageSource) { - if (damageSource instanceof EntityDamageSource entityDamageSource) { - if (entityDamageSource.getAttacker() == this.getOwner() && RatMasterArmorItem.getEquippedPieces(this.getOwner()) >= 4) { - return true; - } + if (damageSource.getAttacker() == this.getOwner() && RatMasterArmorItem.getEquippedPieces(this.getOwner()) >= 4) { + return true; } - if (damageSource == DamageSource.CACTUS || damageSource == DamageSource.SWEET_BERRY_BUSH || damageSource.getAttacker() instanceof EnderDragonEntity || damageSource == DamageSource.CRAMMING) { + if (damageSource.isType(DamageTypes.CACTUS) || damageSource.isType(DamageTypes.SWEET_BERRY_BUSH) || damageSource.getAttacker() instanceof EnderDragonEntity || damageSource.isType(DamageTypes.CRAMMING)) { return true; } else { return super.isInvulnerableTo(damageSource); @@ -952,8 +981,8 @@ protected void loot(ItemEntity item) { @Override protected void playStepSound(BlockPos pos, BlockState state) { - if (!state.getMaterial().isLiquid()) { - BlockState blockState = this.world.getBlockState(pos.up()); + if (!state.isLiquid()) { + BlockState blockState = this.getWorld().getBlockState(pos.up()); BlockSoundGroup blockSoundGroup = blockState.isOf(Blocks.SNOW) ? blockState.getSoundGroup() : state.getSoundGroup(); this.playSound(blockSoundGroup.getStepSound(), blockSoundGroup.getVolume() * 0.01F, blockSoundGroup.getPitch()); } @@ -1015,25 +1044,30 @@ public void removeCurrentActionGoal() { this.action = null; } + @Override + public EntityView getEntityView() { + return this.getWorld(); + } + public enum Type { - WILD(new Identifier(RatsMischief.MOD_ID, "textures/entity/wild.png")), - ALBINO(new Identifier(RatsMischief.MOD_ID, "textures/entity/albino.png")), - BLACK(new Identifier(RatsMischief.MOD_ID, "textures/entity/black.png")), - GREY(new Identifier(RatsMischief.MOD_ID, "textures/entity/grey.png")), - HUSKY(new Identifier(RatsMischief.MOD_ID, "textures/entity/husky.png")), - LIGHT_BROWN(new Identifier(RatsMischief.MOD_ID, "textures/entity/light_brown.png")), - BLUE(new Identifier(RatsMischief.MOD_ID, "textures/entity/blue.png")), - GOLD(new Identifier(RatsMischief.MOD_ID, "textures/entity/gold.png")), + WILD(RatsMischief.id("textures/entity/wild.png")), + ALBINO(RatsMischief.id("textures/entity/albino.png")), + BLACK(RatsMischief.id("textures/entity/black.png")), + GREY(RatsMischief.id("textures/entity/grey.png")), + HUSKY(RatsMischief.id("textures/entity/husky.png")), + LIGHT_BROWN(RatsMischief.id("textures/entity/light_brown.png")), + BLUE(RatsMischief.id("textures/entity/blue.png")), + GOLD(RatsMischief.id("textures/entity/gold.png")), RAT_KID(null), - DOCTOR4T(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/doctor4t.png")), - ASTRONYU(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/astronyu.png")), + DOCTOR4T(RatsMischief.id("textures/entity/named/doctor4t.png")), + ASTRONYU(RatsMischief.id("textures/entity/named/astronyu.png")), - REMY(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/remy.png")), - RATATER(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/ratater.png")), - JERMA(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/jerma.png")), - BIGGIE_CHEESE(new Identifier(RatsMischief.MOD_ID, "textures/entity/named/biggie_cheese.png")); + REMY(RatsMischief.id("textures/entity/named/remy.png")), + RATATER(RatsMischief.id("textures/entity/named/ratater.png")), + JERMA(RatsMischief.id("textures/entity/named/jerma.png")), + BIGGIE_CHEESE(RatsMischief.id("textures/entity/named/biggie_cheese.png")); public final Identifier ratTexture; @@ -1078,7 +1112,7 @@ public boolean canStart() { } else if (RatEntity.this.getRandom().nextInt(10) != 0) { return false; } else { - List list = RatEntity.this.world.getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); + List list = RatEntity.this.getWorld().getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); return !list.isEmpty() && RatEntity.this.getEquippedStack(EquipmentSlot.MAINHAND).isEmpty(); } } else { @@ -1088,7 +1122,7 @@ public boolean canStart() { @Override public void tick() { - List list = RatEntity.this.world.getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); + List list = RatEntity.this.getWorld().getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); ItemStack itemStack = RatEntity.this.getEquippedStack(EquipmentSlot.MAINHAND); if (itemStack.isEmpty() && !list.isEmpty()) { RatEntity.this.getNavigation().startMovingTo(list.get(0), 1); @@ -1097,7 +1131,7 @@ public void tick() { @Override public void start() { - List list = RatEntity.this.world.getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); + List list = RatEntity.this.getWorld().getEntitiesByClass(ItemEntity.class, RatEntity.this.getBoundingBox().expand(10.0D, 10.0D, 10.0D), RatEntity.PICKABLE_DROP_FILTER); if (!list.isEmpty()) { RatEntity.this.getNavigation().startMovingTo(list.get(0), 1); } @@ -1124,7 +1158,7 @@ public void tick() { @Override public boolean canStart() { if (RatEntity.this.getOwner() instanceof PlayerRatOwner playerRatOwner) { - if (!playerRatOwner.shouldBringItems()) { + if (!playerRatOwner.mischief$shouldBringItems()) { return false; } } diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/BreedGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/BreedGoal.java index d5acbe50..73e6e308 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/BreedGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/BreedGoal.java @@ -24,7 +24,7 @@ public boolean canStart() { @Override public void start() { - if (!this.rat.getMainHandStack().isEmpty() && !this.rat.getWorld().getEntitiesByClass(AnimalEntity.class, this.rat.getBoundingBox().expand(16, 4, 16), animalEntity -> !this.rat.world.isClient() && animalEntity.getBreedingAge() == 0 && animalEntity.canEat() && animalEntity.isBreedingItem(this.rat.getMainHandStack())).isEmpty()) { + if (!this.rat.getMainHandStack().isEmpty() && !this.rat.getWorld().getEntitiesByClass(AnimalEntity.class, this.rat.getBoundingBox().expand(16, 4, 16), animalEntity -> !this.rat.getWorld().isClient() && animalEntity.getBreedingAge() == 0 && animalEntity.canEat() && animalEntity.isBreedingItem(this.rat.getMainHandStack())).isEmpty()) { List animalList = this.rat.getWorld().getEntitiesByClass(AnimalEntity.class, this.rat.getBoundingBox().expand(16, 4, 16), animalEntity -> animalEntity.getBreedingAge() == 0 && animalEntity.canEat() && animalEntity.isBreedingItem(this.rat.getMainHandStack())); AnimalEntity closestAnimal = animalList.get(0); for (AnimalEntity animalEntity : animalList) { @@ -42,9 +42,9 @@ public void tick() { ItemStack itemStack = this.rat.getEquippedStack(EquipmentSlot.MAINHAND); if (this.rat.squaredDistanceTo(this.target.getX(), this.target.getY(), this.target.getZ()) <= 5) { - if (this.rat.getOwner() instanceof PlayerEntity) { + if (this.rat.getOwner() instanceof PlayerEntity owner) { itemStack.decrement(1); - this.target.lovePlayer((PlayerEntity) this.rat.getOwner()); + this.target.lovePlayer(owner); } this.target = null; diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/ChaseForFunGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/ChaseForFunGoal.java index cca3074c..3403e64c 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/ChaseForFunGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/ChaseForFunGoal.java @@ -62,7 +62,7 @@ protected Box getSearchBox(double distance) { } protected void findClosestTarget() { - this.targetEntity = this.mob.world.getClosestEntity(this.targetClass, this.targetPredicate, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ(), this.getSearchBox(10)); + this.targetEntity = this.mob.getWorld().getClosestEntity(this.targetClass, this.targetPredicate, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ(), this.getSearchBox(10)); } public void setTargetEntity(@Nullable LivingEntity targetEntity) { diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/DigGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/DigGoal.java index df3ed8f4..7f8afd73 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/DigGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/DigGoal.java @@ -33,14 +33,14 @@ public boolean canStart() { ItemStack itemStack = this.rat.getEquippedStack(EquipmentSlot.MAINHAND); if (itemStack.isEmpty()) { for (BlockPos blockPos : BlockPos.iterateOutwards(this.rat.getBlockPos(), 8, 2, 8)) { - BlockState blockState = this.rat.world.getBlockState(blockPos); + BlockState blockState = this.rat.getWorld().getBlockState(blockPos); if (blockState.getBlock() == this.targetBlock) { int strength = 0; StatusEffectInstance effect = this.rat.getStatusEffect(StatusEffects.STRENGTH); if (effect != null) { strength = effect.getAmplifier() + 1; } - if (blockState.getHardness(this.rat.world, blockPos) >= 0 && blockState.getHardness(this.rat.world, blockPos) <= 1f + strength) { + if (blockState.getHardness(this.rat.getWorld(), blockPos) >= 0 && blockState.getHardness(this.rat.getWorld(), blockPos) <= 1f + strength) { if (this.rat.getNavigation().startMovingTo(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 1f)) { this.targetBlockPos = blockPos; return true; @@ -58,7 +58,7 @@ public void tick() { ItemStack itemStack = this.rat.getEquippedStack(EquipmentSlot.MAINHAND); if (itemStack.isEmpty()) { - BlockState blockState = this.rat.world.getBlockState(this.targetBlockPos); + BlockState blockState = this.rat.getWorld().getBlockState(this.targetBlockPos); if (blockState.getBlock() != this.targetBlock) { this.canStart(); return; @@ -74,10 +74,10 @@ public void tick() { float progressIncrease = 0.015f + 0.003f * haste; progressIncrease *= RatMasterArmorItem.getMiningSpeedMultiplier(this.rat.getOwner()); this.breakProgress += progressIncrease; - this.rat.world.setBlockBreakingInfo(this.rat.getId(), this.targetBlockPos, (int) (this.breakProgress / this.rat.world.getBlockState(this.targetBlockPos).getHardness(this.rat.world, this.targetBlockPos) * 9)); - if (this.breakProgress >= this.rat.world.getBlockState(this.targetBlockPos).getHardness(this.rat.world, this.targetBlockPos)) { - this.rat.world.setBlockBreakingInfo(this.rat.getId(), this.targetBlockPos, -1); - this.rat.world.breakBlock(this.targetBlockPos, true, this.rat); + this.rat.getWorld().setBlockBreakingInfo(this.rat.getId(), this.targetBlockPos, (int) (this.breakProgress / this.rat.getWorld().getBlockState(this.targetBlockPos).getHardness(this.rat.getWorld(), this.targetBlockPos) * 9)); + if (this.breakProgress >= this.rat.getWorld().getBlockState(this.targetBlockPos).getHardness(this.rat.getWorld(), this.targetBlockPos)) { + this.rat.getWorld().setBlockBreakingInfo(this.rat.getId(), this.targetBlockPos, -1); + this.rat.getWorld().breakBlock(this.targetBlockPos, true, this.rat); this.targetBlockPos = null; } } else { diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/EatToHealGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/EatToHealGoal.java index 1cb0b25c..30d8a6de 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/EatToHealGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/EatToHealGoal.java @@ -31,7 +31,7 @@ public boolean canStart() { @Override public void tick() { - if (!this.rat.world.isClient() && this.rat.isEating()) { + if (!this.rat.getWorld().isClient() && this.rat.isEating()) { if (!this.rat.getMoveControl().isMoving()) { super.tick(); @@ -39,10 +39,10 @@ public void tick() { if (this.eatingTicks % 4 == 0 && this.eatingTicks > 0) { if (this.rat.getMainHandStack().getItem().getUseAction(this.rat.getMainHandStack()) == UseAction.DRINK) { - this.rat.world.playSoundFromEntity(null, this.rat, this.rat.getMainHandStack().getItem().getDrinkSound(), SoundCategory.NEUTRAL, 0.01F, this.rat.getRandom().nextFloat() * 0.4F + 0.8F); + this.rat.getWorld().playSoundFromEntity(null, this.rat, this.rat.getMainHandStack().getItem().getDrinkSound(), SoundCategory.NEUTRAL, 0.01F, this.rat.getRandom().nextFloat() * 0.4F + 0.8F); } else if (this.rat.getMainHandStack().getItem().getUseAction(this.rat.getMainHandStack()) == UseAction.EAT) { - ((ServerWorld) this.rat.world).spawnParticles(new ItemStackParticleEffect(ParticleTypes.ITEM, this.rat.getMainHandStack()), this.rat.getX() + this.rat.getRandom().nextGaussian() / 20f, this.rat.getY() + this.rat.getRandom().nextGaussian() / 20f, this.rat.getZ() + this.rat.getRandom().nextGaussian() / 20f, 5, this.rat.getRandom().nextGaussian() / 20f, 0.2D + this.rat.getRandom().nextGaussian() / 20f, this.rat.getRandom().nextGaussian() / 20f, 0.025f); - this.rat.world.playSoundFromEntity(null, this.rat, this.rat.getMainHandStack().getItem().getEatSound(), SoundCategory.NEUTRAL, 0.01F, this.rat.getRandom().nextFloat() * 0.4F + 0.8F); + ((ServerWorld) this.rat.getWorld()).spawnParticles(new ItemStackParticleEffect(ParticleTypes.ITEM, this.rat.getMainHandStack()), this.rat.getX() + this.rat.getRandom().nextGaussian() / 20f, this.rat.getY() + this.rat.getRandom().nextGaussian() / 20f, this.rat.getZ() + this.rat.getRandom().nextGaussian() / 20f, 5, this.rat.getRandom().nextGaussian() / 20f, 0.2D + this.rat.getRandom().nextGaussian() / 20f, this.rat.getRandom().nextGaussian() / 20f, 0.025f); + this.rat.getWorld().playSoundFromEntity(null, this.rat, this.rat.getMainHandStack().getItem().getEatSound(), SoundCategory.NEUTRAL, 0.01F, this.rat.getRandom().nextFloat() * 0.4F + 0.8F); } } @@ -50,7 +50,7 @@ public void tick() { if (this.rat.getMainHandStack().getItem() instanceof PotionItem) { ItemStack stack = this.rat.getMainHandStack(); - if (!this.rat.world.isClient()) { + if (!this.rat.getWorld().isClient()) { List list = PotionUtil.getPotionEffects(stack); for (StatusEffectInstance statusEffectInstance : list) { @@ -72,7 +72,7 @@ public void tick() { this.rat.getMainHandStack().getItem().getFoodComponent().getStatusEffects().forEach(statusEffectInstanceFloatPair -> { this.rat.addStatusEffect(statusEffectInstanceFloatPair.getFirst()); }); - this.rat.getMainHandStack().getItem().finishUsing(this.rat.getMainHandStack(), this.rat.world, this.rat); + this.rat.getMainHandStack().getItem().finishUsing(this.rat.getMainHandStack(), this.rat.getWorld(), this.rat); } this.rat.setEating(false); diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/FollowOwnerRatGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/FollowOwnerRatGoal.java index 5958772e..50d6ed30 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/FollowOwnerRatGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/FollowOwnerRatGoal.java @@ -2,10 +2,14 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import net.minecraft.block.BlockState; -import net.minecraft.block.LeavesBlock; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.goal.Goal; -import net.minecraft.entity.ai.pathing.*; +import net.minecraft.entity.ai.pathing.BirdNavigation; +import net.minecraft.entity.ai.pathing.EntityNavigation; +import net.minecraft.entity.ai.pathing.LandPathNodeMaker; +import net.minecraft.entity.ai.pathing.MobNavigation; +import net.minecraft.entity.ai.pathing.PathNodeType; +import net.minecraft.registry.tag.BlockTags; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldView; @@ -25,7 +29,7 @@ public class FollowOwnerRatGoal extends Goal { public FollowOwnerRatGoal(RatEntity rat, double speed, float minDistance, float maxDistance, boolean leavesAllowed) { this.rat = rat; - this.world = rat.world; + this.world = rat.getWorld(); this.speed = speed; this.navigation = rat.getNavigation(); this.minDistance = minDistance; @@ -129,7 +133,7 @@ private boolean canTeleportTo(BlockPos pos) { return false; } else { BlockState blockState = this.world.getBlockState(pos.down()); - if (!this.leavesAllowed && blockState.getBlock() instanceof LeavesBlock) { + if (!this.leavesAllowed && blockState.isIn(BlockTags.LEAVES)) { return false; } else { BlockPos blockPos = pos.subtract(this.rat.getBlockPos()); diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/HarvestPlantMealGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/HarvestPlantMealGoal.java index 0a7ed986..4bcb7869 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/HarvestPlantMealGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/HarvestPlantMealGoal.java @@ -6,10 +6,11 @@ import net.minecraft.block.FarmlandBlock; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.ai.goal.Goal; -import net.minecraft.item.AliasedBlockItem; +import net.minecraft.item.BlockItem; import net.minecraft.item.BoneMealItem; import net.minecraft.item.ItemStack; import net.minecraft.particle.ParticleTypes; +import net.minecraft.registry.tag.BlockTags; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; @@ -30,23 +31,23 @@ public HarvestPlantMealGoal(RatEntity rat) { public boolean canStart() { this.targetBlockPos = null; - if (this.rat.getTarget() == null && this.rat.getAttacker() == null && !this.rat.isSitting() && this.rat.isTamed() && (this.rat.getEquippedStack(EquipmentSlot.MAINHAND).isEmpty() || (this.rat.getEquippedStack(EquipmentSlot.MAINHAND).getItem() instanceof AliasedBlockItem && ((AliasedBlockItem) this.rat.getEquippedStack(EquipmentSlot.MAINHAND).getItem()).getBlock() instanceof CropBlock) || this.rat.getEquippedStack(EquipmentSlot.MAINHAND).getItem() instanceof BoneMealItem)) { + if (this.rat.getTarget() == null && this.rat.getAttacker() == null && !this.rat.isSitting() && this.rat.isTamed() && (this.rat.getEquippedStack(EquipmentSlot.MAINHAND).isEmpty() || (this.rat.getEquippedStack(EquipmentSlot.MAINHAND).getItem() instanceof BlockItem bi && bi.getBlock().getDefaultState().isIn(BlockTags.CROPS)) || this.rat.getEquippedStack(EquipmentSlot.MAINHAND).getItem() instanceof BoneMealItem)) { ItemStack itemStack = this.rat.getEquippedStack(EquipmentSlot.MAINHAND); for (BlockPos blockPos : BlockPos.iterateOutwards(this.rat.getBlockPos(), 8, 2, 8)) { if (itemStack.isEmpty()) { // harvest - BlockState blockState = this.rat.world.getBlockState(blockPos); - if (blockState.getBlock() instanceof CropBlock && ((CropBlock) blockState.getBlock()).isMature(blockState)) { + BlockState blockState = this.rat.getWorld().getBlockState(blockPos); + if (blockState.getBlock() instanceof CropBlock crop && crop.isMature(blockState)) { if (this.rat.getNavigation().startMovingTo(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 1f)) { this.targetBlockPos = blockPos; return true; } } - } else if (itemStack.getItem() instanceof AliasedBlockItem && ((AliasedBlockItem) itemStack.getItem()).getBlock() instanceof CropBlock) { + } else if (itemStack.getItem() instanceof BlockItem bi && bi.getBlock() instanceof CropBlock) { // plant - BlockState blockState = this.rat.world.getBlockState(blockPos.add(0, -1, 0)); - if (blockState.getBlock() instanceof FarmlandBlock && this.rat.world.getBlockState(blockPos).isAir()) { + BlockState blockState = this.rat.getWorld().getBlockState(blockPos.add(0, -1, 0)); + if (blockState.getBlock() instanceof FarmlandBlock && this.rat.getWorld().getBlockState(blockPos).isAir()) { if (this.rat.getNavigation().startMovingTo(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 1f)) { this.targetBlockPos = blockPos; return true; @@ -54,8 +55,8 @@ public boolean canStart() { } } else if (itemStack.getItem() instanceof BoneMealItem) { // bonemeal - BlockState blockState = this.rat.world.getBlockState(blockPos); - if (blockState.getBlock() instanceof CropBlock && ((CropBlock) blockState.getBlock()).isFertilizable(this.rat.world, blockPos, this.rat.world.getBlockState(blockPos), this.rat.world.isClient())) { + BlockState blockState = this.rat.getWorld().getBlockState(blockPos); + if (blockState.getBlock() instanceof CropBlock crop && crop.isFertilizable(this.rat.getWorld(), blockPos, this.rat.getWorld().getBlockState(blockPos), this.rat.getWorld().isClient())) { if (this.rat.getNavigation().startMovingTo(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 1f)) { this.targetBlockPos = blockPos; return true; @@ -74,26 +75,26 @@ public void tick() { if (itemStack.isEmpty()) { // harvest - BlockState blockState = this.rat.world.getBlockState(this.targetBlockPos); - if (!(blockState.getBlock() instanceof CropBlock && ((CropBlock) blockState.getBlock()).isMature(blockState))) { + BlockState blockState = this.rat.getWorld().getBlockState(this.targetBlockPos); + if (!(blockState.getBlock() instanceof CropBlock crop && crop.isMature(blockState))) { this.canStart(); } if (this.rat.squaredDistanceTo(this.targetBlockPos.getX(), this.targetBlockPos.getY(), this.targetBlockPos.getZ()) <= 5) { - this.rat.world.breakBlock(this.targetBlockPos, true, this.rat); + this.rat.getWorld().breakBlock(this.targetBlockPos, true, this.rat); this.targetBlockPos = null; } else { this.rat.getNavigation().startMovingTo(this.targetBlockPos.getX(), this.targetBlockPos.getY(), this.targetBlockPos.getZ(), 1D); } - } else if (itemStack.getItem() instanceof AliasedBlockItem && ((AliasedBlockItem) itemStack.getItem()).getBlock() instanceof CropBlock) { + } else if (itemStack.getItem() instanceof BlockItem bi && bi.getBlock() instanceof CropBlock) { // plant - BlockState blockState = this.rat.world.getBlockState(this.targetBlockPos.add(0, -1, 0)); - if (!(blockState.getBlock() instanceof FarmlandBlock && this.rat.world.getBlockState(this.targetBlockPos).isAir())) { + BlockState blockState = this.rat.getWorld().getBlockState(this.targetBlockPos.add(0, -1, 0)); + if (!(blockState.getBlock() instanceof FarmlandBlock && this.rat.getWorld().getBlockState(this.targetBlockPos).isAir())) { this.canStart(); } if (this.rat.squaredDistanceTo(this.targetBlockPos.getX(), this.targetBlockPos.getY(), this.targetBlockPos.getZ()) <= 5) { - this.rat.world.setBlockState(this.targetBlockPos, ((AliasedBlockItem) itemStack.getItem()).getBlock().getDefaultState()); + this.rat.getWorld().setBlockState(this.targetBlockPos, bi.getBlock().getDefaultState()); this.rat.getEquippedStack(EquipmentSlot.MAINHAND).decrement(1); this.targetBlockPos = null; } else { @@ -101,13 +102,13 @@ public void tick() { } } else if (itemStack.getItem() instanceof BoneMealItem) { // bonemeal - BlockState blockState = this.rat.world.getBlockState(this.targetBlockPos); - if (blockState.getBlock() instanceof CropBlock && ((CropBlock) blockState.getBlock()).isFertilizable(this.rat.world, this.targetBlockPos, this.rat.world.getBlockState(this.targetBlockPos), this.rat.world.isClient())) { + BlockState blockState = this.rat.getWorld().getBlockState(this.targetBlockPos); + if (blockState.getBlock() instanceof CropBlock crop && crop.isFertilizable(this.rat.getWorld(), this.targetBlockPos, this.rat.getWorld().getBlockState(this.targetBlockPos), this.rat.getWorld().isClient())) { this.canStart(); } if (this.rat.squaredDistanceTo(this.targetBlockPos.getX(), this.targetBlockPos.getY(), this.targetBlockPos.getZ()) <= 5) { - BoneMealItem.useOnFertilizable(itemStack, this.rat.world, this.targetBlockPos); + BoneMealItem.useOnFertilizable(itemStack, this.rat.getWorld(), this.targetBlockPos); ServerWorld serverWorld = (ServerWorld) this.rat.getWorld(); diff --git a/src/main/java/ladysnake/ratsmischief/common/entity/ai/RatMeleeAttackGoal.java b/src/main/java/ladysnake/ratsmischief/common/entity/ai/RatMeleeAttackGoal.java index 9d3b0cb4..8f73cff1 100644 --- a/src/main/java/ladysnake/ratsmischief/common/entity/ai/RatMeleeAttackGoal.java +++ b/src/main/java/ladysnake/ratsmischief/common/entity/ai/RatMeleeAttackGoal.java @@ -37,7 +37,7 @@ public boolean canStart() { return false; } - long l = this.rat.world.getTime(); + long l = this.rat.getWorld().getTime(); if (l - this.lastUpdateTime < 20L) { return false; } else { @@ -74,7 +74,7 @@ public boolean shouldContinue() { } else if (!this.rat.isInWalkTargetRange(livingEntity.getBlockPos())) { return false; } else { - return !(livingEntity instanceof PlayerEntity) || !livingEntity.isSpectator() && !((PlayerEntity) livingEntity).isCreative(); + return !(livingEntity instanceof PlayerEntity player) || !livingEntity.isSpectator() && !player.isCreative(); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModBlocks.java b/src/main/java/ladysnake/ratsmischief/common/init/ModBlocks.java index 38922399..ca27d6aa 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModBlocks.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModBlocks.java @@ -3,8 +3,9 @@ import ladysnake.ratsmischief.common.RatsMischief; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; import java.util.LinkedHashMap; @@ -16,11 +17,11 @@ public interface ModBlocks { // Block MOD_BLOCK = createBlock("mod_block", new ModBlock(QuiltBlockSettings.of(Material.METAL, MapColor.DEEPSLATE_GRAY).strength(-1.0F, 3600000.0F).sounds(BlockSoundGroup.COPPER)), true); static void initialize() { - BLOCKS.keySet().forEach(block -> Registry.register(Registry.BLOCK, BLOCKS.get(block), block)); + BLOCKS.keySet().forEach(block -> Registry.register(Registries.BLOCK, BLOCKS.get(block), block)); } private static T createBlock(String name, T block, boolean createItem) { - BLOCKS.put(block, new Identifier(RatsMischief.MOD_ID, name)); + BLOCKS.put(block, RatsMischief.id(name)); if (createItem) { ModItems.ITEMS.put(new BlockItem(block, new QuiltItemSettings()), BLOCKS.get(block)); } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModDamageSources.java b/src/main/java/ladysnake/ratsmischief/common/init/ModDamageSources.java deleted file mode 100644 index 2de17d61..00000000 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModDamageSources.java +++ /dev/null @@ -1,11 +0,0 @@ -package ladysnake.ratsmischief.common.init; - -import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.damage.EntityDamageSource; - -public interface ModDamageSources { - static DamageSource ratDamage(RatEntity rat) { - return new EntityDamageSource("rat", rat); - } -} diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModDamageTypes.java b/src/main/java/ladysnake/ratsmischief/common/init/ModDamageTypes.java new file mode 100644 index 00000000..0f48e12f --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModDamageTypes.java @@ -0,0 +1,16 @@ +package ladysnake.ratsmischief.common.init; + +import ladysnake.ratsmischief.common.RatsMischief; +import ladysnake.ratsmischief.common.entity.RatEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.damage.DamageType; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; + +public interface ModDamageTypes { + RegistryKey RAT = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, RatsMischief.id("rat")); + + static DamageSource ratDamage(RatEntity rat) { + return new DamageSource(rat.getWorld().getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).getHolderOrThrow(RAT), rat); + } +} diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModEnchantments.java b/src/main/java/ladysnake/ratsmischief/common/init/ModEnchantments.java index a081a530..95d16fc9 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModEnchantments.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModEnchantments.java @@ -4,8 +4,9 @@ import ladysnake.ratsmischief.common.enchantments.RatCurseEnchantment; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.EquipmentSlot; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import java.util.LinkedHashMap; import java.util.Map; @@ -17,11 +18,11 @@ public interface ModEnchantments { @SuppressWarnings("SameParameterValue") private static Enchantment createEnchantment(String name, Enchantment entity) { - ENCHANTMENTS.put(entity, new Identifier(RatsMischief.MOD_ID, name)); + ENCHANTMENTS.put(entity, RatsMischief.id(name)); return entity; } static void initialize() { - ENCHANTMENTS.keySet().forEach(entityType -> Registry.register(Registry.ENCHANTMENT, ENCHANTMENTS.get(entityType), entityType)); + ENCHANTMENTS.keySet().forEach(entityType -> Registry.register(Registries.ENCHANTMENT, ENCHANTMENTS.get(entityType), entityType)); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModEntities.java b/src/main/java/ladysnake/ratsmischief/common/init/ModEntities.java index b97cb41f..61c48569 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModEntities.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModEntities.java @@ -5,8 +5,9 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import org.quiltmc.qsl.entity.api.QuiltEntityTypeBuilder; import java.util.LinkedHashMap; @@ -19,11 +20,11 @@ public interface ModEntities { EntityType RAT = createEntity("rat", QuiltEntityTypeBuilder.createMob().entityFactory(RatEntity::new).defaultAttributes(RatEntity.createRatAttributes()).setDimensions(EntityDimensions.changing(0.6F, 0.4F)).maxChunkTrackingRange(128).build()); private static > T createEntity(String name, T entity) { - ENTITIES.put(entity, new Identifier(RatsMischief.MOD_ID, name)); + ENTITIES.put(entity, RatsMischief.id(name)); return entity; } static void initialize() { - ENTITIES.keySet().forEach(entityType -> Registry.register(Registry.ENTITY_TYPE, ENTITIES.get(entityType), entityType)); + ENTITIES.keySet().forEach(entityType -> Registry.register(Registries.ENTITY_TYPE, ENTITIES.get(entityType), entityType)); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModItemGroup.java b/src/main/java/ladysnake/ratsmischief/common/init/ModItemGroup.java index 223c538a..79c16c72 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModItemGroup.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModItemGroup.java @@ -14,7 +14,7 @@ // public static ItemGroup MOD_ITEMS; // // public static void initialize() { -// MOD_ITEMS = FabricItemGroup.builder(new Identifier(RatsMischief.MOD_ID, "items")) +// MOD_ITEMS = FabricItemGroup.builder(RatsMischief.id("items")) // .name(Text.literal("Explosive Ideas")) // .icon(() -> new ItemStack(Items.TNT)) // .build(); diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModItems.java b/src/main/java/ladysnake/ratsmischief/common/init/ModItems.java index 00428f69..b1f31d3b 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModItems.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModItems.java @@ -1,13 +1,22 @@ package ladysnake.ratsmischief.common.init; import ladysnake.ratsmischief.common.RatsMischief; -import ladysnake.ratsmischief.common.item.*; -import net.minecraft.entity.EquipmentSlot; +import ladysnake.ratsmischief.common.item.RatItem; +import ladysnake.ratsmischief.common.item.RatMasterArmorItem; +import ladysnake.ratsmischief.common.item.RatMasterCloakItem; +import ladysnake.ratsmischief.common.item.RatMasterHoodItem; +import ladysnake.ratsmischief.common.item.RatMasterMaskItem; +import ladysnake.ratsmischief.common.item.RatMasterMirrorItem; +import ladysnake.ratsmischief.common.item.RatMasterOcarinaItem; +import ladysnake.ratsmischief.common.item.RatPouchItem; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.minecraft.item.ArmorItem; import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemGroups; import net.minecraft.item.SpawnEggItem; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; import java.util.LinkedHashMap; @@ -19,31 +28,52 @@ public interface ModItems { // Item MOD_ITEM = createItem("mod_item", new ModItem(new QuiltItemSettings())); Item RAT = createItem("rat", new RatItem(new QuiltItemSettings().maxCount(1))); - Item RAT_SPAWN_EGG = createItem("rat_spawn_egg", new SpawnEggItem(ModEntities.RAT, 0x2E1C1C, 0x241317, new QuiltItemSettings().group(ItemGroup.MISC))); - - Item LEATHER_RAT_POUCH = createItem("leather_rat_pouch", new RatPouchItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1), 5)); - Item TWISTED_RAT_POUCH = createItem("twisted_rat_pouch", new RatPouchItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1), 10)); - Item PURPUR_RAT_POUCH = createItem("purpur_rat_pouch", new RatPouchItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1), 15)); - Item RAT_MASTER_POUCH = createItem("rat_master_pouch", new RatPouchItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1), 20)); - - Item CLOTHED_INGOT = createItem("clothed_ingot", new Item(new QuiltItemSettings().group(ItemGroup.MISC))); - Item RAT_MASTER_HOOD = createItem("rat_master_hood", new RatMasterHoodItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, EquipmentSlot.HEAD, new QuiltItemSettings().group(ItemGroup.COMBAT))); - Item RAT_MASTER_CLOAK = createItem("rat_master_cloak", new RatMasterCloakItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, EquipmentSlot.CHEST, new QuiltItemSettings().group(ItemGroup.COMBAT))); - Item RAT_MASTER_BREECHES = createItem("rat_master_breeches", new RatMasterArmorItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, EquipmentSlot.LEGS, new QuiltItemSettings().group(ItemGroup.COMBAT))); - Item RAT_MASTER_GREAVES = createItem("rat_master_greaves", new RatMasterArmorItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, EquipmentSlot.FEET, new QuiltItemSettings().group(ItemGroup.COMBAT))); - Item RAT_MASTER_MIRROR = createItem("rat_master_mirror", new RatMasterMirrorItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1))); - Item RAT_MASTER_OCARINA = createItem("rat_master_ocarina", new RatMasterOcarinaItem(new QuiltItemSettings().group(ItemGroup.TOOLS).maxCount(1))); - Item RAT_MASTER_MASK = createItem("rat_master_mask", new RatMasterMaskItem(new QuiltItemSettings().group(ItemGroup.COMBAT).maxCount(1))); + Item RAT_SPAWN_EGG = createItem("rat_spawn_egg", new SpawnEggItem(ModEntities.RAT, 0x2E1C1C, 0x241317, new QuiltItemSettings())); + + Item LEATHER_RAT_POUCH = createItem("leather_rat_pouch", new RatPouchItem(new QuiltItemSettings().maxCount(1), 5)); + Item TWISTED_RAT_POUCH = createItem("twisted_rat_pouch", new RatPouchItem(new QuiltItemSettings().maxCount(1), 10)); + Item PURPUR_RAT_POUCH = createItem("purpur_rat_pouch", new RatPouchItem(new QuiltItemSettings().maxCount(1), 15)); + Item RAT_MASTER_POUCH = createItem("rat_master_pouch", new RatPouchItem(new QuiltItemSettings().maxCount(1), 20)); + + Item CLOTHED_INGOT = createItem("clothed_ingot", new Item(new QuiltItemSettings())); + Item RAT_MASTER_HOOD = createItem("rat_master_hood", new RatMasterHoodItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, ArmorItem.ArmorSlot.HELMET, new QuiltItemSettings())); + Item RAT_MASTER_CLOAK = createItem("rat_master_cloak", new RatMasterCloakItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, ArmorItem.ArmorSlot.CHESTPLATE, new QuiltItemSettings())); + Item RAT_MASTER_BREECHES = createItem("rat_master_breeches", new RatMasterArmorItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, ArmorItem.ArmorSlot.LEGGINGS, new QuiltItemSettings())); + Item RAT_MASTER_GREAVES = createItem("rat_master_greaves", new RatMasterArmorItem(RatMasterArmorItem.RatMasterArmorMaterial.INSTANCE, ArmorItem.ArmorSlot.BOOTS, new QuiltItemSettings())); + Item RAT_MASTER_MIRROR = createItem("rat_master_mirror", new RatMasterMirrorItem(new QuiltItemSettings().maxCount(1))); + Item RAT_MASTER_OCARINA = createItem("rat_master_ocarina", new RatMasterOcarinaItem(new QuiltItemSettings().maxCount(1))); + Item RAT_MASTER_MASK = createItem("rat_master_mask", new RatMasterMaskItem(new QuiltItemSettings().maxCount(1))); private static T createItem(String name, T item) { - ITEMS.put(item, new Identifier(RatsMischief.MOD_ID, name)); + ITEMS.put(item, RatsMischief.id(name)); return item; } static void initialize() { ITEMS.keySet().forEach(item -> { - Registry.register(Registry.ITEM, ITEMS.get(item), item); + Registry.register(Registries.ITEM, ITEMS.get(item), item); // ModItemGroup.addToItemGroup(ModItemGroup.MOD_ITEMS, item); }); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { + entries.addItem(RAT_MASTER_HOOD); + entries.addItem(RAT_MASTER_CLOAK); + entries.addItem(RAT_MASTER_BREECHES); + entries.addItem(RAT_MASTER_GREAVES); + entries.addItem(RAT_MASTER_MASK); + }); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> { + entries.addItem(CLOTHED_INGOT); + }); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.SPAWN_EGGS).register(entries -> { + entries.addItem(RAT_SPAWN_EGG); + }); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS_AND_UTILITIES).register(entries -> { + entries.addItem(LEATHER_RAT_POUCH); + entries.addItem(TWISTED_RAT_POUCH); + entries.addItem(PURPUR_RAT_POUCH); + entries.addItem(RAT_MASTER_POUCH); + entries.addItem(RAT_MASTER_MIRROR); + entries.addItem(RAT_MASTER_OCARINA); + }); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModLootTables.java b/src/main/java/ladysnake/ratsmischief/common/init/ModLootTables.java index b32258ae..f5ed38cd 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModLootTables.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModLootTables.java @@ -1,42 +1,38 @@ package ladysnake.ratsmischief.common.init; -import ladysnake.ratsmischief.common.RatsMischief; import net.fabricmc.fabric.api.loot.v2.LootTableEvents; -import net.minecraft.enchantment.EnchantmentLevelEntry; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.loot.LootPool; +import net.minecraft.loot.LootTables; import net.minecraft.loot.condition.RandomChanceLootCondition; -import net.minecraft.loot.context.LootContext; import net.minecraft.loot.entry.ItemEntry; -import net.minecraft.loot.function.LootFunction; -import net.minecraft.loot.function.LootFunctionType; +import net.minecraft.loot.function.SetEnchantmentsLootFunction; import net.minecraft.loot.provider.number.ConstantLootNumberProvider; +import net.minecraft.loot.provider.number.LootNumberProvider; public class ModLootTables { - public static final float RAT_CURSE_CHANCE = 0.2f; // 20% + private static final float CLOTHED_INGOT_CHANCE = 0.3f; // 30% + private static final float RAT_CURSE_CHANCE = 0.2f; // 20% + private static final LootNumberProvider CONST_1 = ConstantLootNumberProvider.create(1); public static void initialize() { - LootTableEvents.MODIFY.register((resourceManager, lootManager, identifier, fabricLootSupplierBuilder, lootTableSetter) -> { - if (RatsMischief.ANCIENT_CITY_CHESTS.equals(identifier)) { - fabricLootSupplierBuilder.pool(new LootPool.Builder() - .rolls(ConstantLootNumberProvider.create(1)) - .with(ItemEntry.builder(Items.BOOK).apply(() -> new LootFunction() { - @Override - public LootFunctionType getType() { - throw new UnsupportedOperationException(); - } - - @Override - public ItemStack apply(ItemStack itemStack, LootContext lootContext) { - EnchantmentLevelEntry enchantment = new EnchantmentLevelEntry(ModEnchantments.RAT_CURSE, 1); - return EnchantedBookItem.forEnchantment(enchantment); - } - }).build()) - .conditionally(RandomChanceLootCondition.builder(RAT_CURSE_CHANCE).build()) - .build() - ); + // clothed ingots and rat curse books spawning in ancient city chests + LootTableEvents.MODIFY.register((resourceManager, lootManager, id, supplier, setter) -> { + if (LootTables.ANCIENT_CITY_CHEST.equals(id)) { + { // clothed ingot + LootPool lootPool = LootPool.builder() + .rolls(CONST_1) + .conditionally(RandomChanceLootCondition.builder(CLOTHED_INGOT_CHANCE).build()) + .with(ItemEntry.builder(ModItems.CLOTHED_INGOT).build()).build(); + supplier.pool(lootPool); + } + { // rat curse book + LootPool lootPool = LootPool.builder() + .rolls(CONST_1) + .conditionally(RandomChanceLootCondition.builder(RAT_CURSE_CHANCE).build()) + .with(ItemEntry.builder(Items.ENCHANTED_BOOK).apply((new SetEnchantmentsLootFunction.Builder()).enchantment(ModEnchantments.RAT_CURSE, CONST_1)).build()).build(); + supplier.pool(lootPool); + } } }); } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModParticles.java b/src/main/java/ladysnake/ratsmischief/common/init/ModParticles.java index 0f8fa0f9..9b4a2340 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModParticles.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModParticles.java @@ -1,8 +1,9 @@ package ladysnake.ratsmischief.common.init; import net.minecraft.particle.ParticleType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import java.util.function.BiConsumer; @@ -11,7 +12,7 @@ public interface ModParticles { // DefaultParticleType DEFAULT_PARTICLE = FabricParticleTypes.simple(true); static void init() { - initParticles(bind(Registry.PARTICLE_TYPE)); + initParticles(bind(Registries.PARTICLE_TYPE)); } static void registerFactories() { diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModSoundEvents.java b/src/main/java/ladysnake/ratsmischief/common/init/ModSoundEvents.java index 499d4a1e..74671c07 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModSoundEvents.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModSoundEvents.java @@ -1,9 +1,10 @@ package ladysnake.ratsmischief.common.init; import ladysnake.ratsmischief.common.RatsMischief; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import java.util.LinkedHashMap; import java.util.Map; @@ -19,12 +20,12 @@ public interface ModSoundEvents { static void initialize() { SOUND_EVENTS.keySet().forEach(soundEvent -> { - Registry.register(Registry.SOUND_EVENT, SOUND_EVENTS.get(soundEvent), soundEvent); + Registry.register(Registries.SOUND_EVENT, SOUND_EVENTS.get(soundEvent), soundEvent); }); } private static SoundEvent createSoundEvent(String path) { - SoundEvent soundEvent = new SoundEvent(new Identifier(RatsMischief.MOD_ID, path)); + SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(RatsMischief.id(path)); SOUND_EVENTS.put(soundEvent, new Identifier(RatsMischief.MOD_ID, path)); return soundEvent; } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModStatusEffects.java b/src/main/java/ladysnake/ratsmischief/common/init/ModStatusEffects.java index d8c6271e..0a0a3a99 100644 --- a/src/main/java/ladysnake/ratsmischief/common/init/ModStatusEffects.java +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModStatusEffects.java @@ -1,12 +1,13 @@ package ladysnake.ratsmischief.common.init; import ladysnake.ratsmischief.common.RatsMischief; +import ladysnake.ratsmischief.common.effect.RatCurseCooldownStatusEffect; import ladysnake.ratsmischief.common.effect.RatCurseStatusEffect; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import xyz.amymialee.mialeemisc.effects.OpenStatusEffect; import java.util.LinkedHashMap; import java.util.Map; @@ -15,14 +16,14 @@ public interface ModStatusEffects { Map EFFECTS = new LinkedHashMap<>(); StatusEffect RAT_CURSE = createStatusEffect("rat_curse", new RatCurseStatusEffect(StatusEffectType.NEUTRAL, 0x31363F)); - StatusEffect RAT_CURSE_COOLDOWN = createStatusEffect("rat_curse_cooldown", new OpenStatusEffect(StatusEffectType.NEUTRAL, 0x31363F)); + StatusEffect RAT_CURSE_COOLDOWN = createStatusEffect("rat_curse_cooldown", new RatCurseCooldownStatusEffect(StatusEffectType.NEUTRAL, 0x31363F)); private static T createStatusEffect(String name, T effect) { - EFFECTS.put(effect, new Identifier(RatsMischief.MOD_ID, name)); + EFFECTS.put(effect, RatsMischief.id(name)); return effect; } static void initialize() { - EFFECTS.keySet().forEach(item -> Registry.register(Registry.STATUS_EFFECT, EFFECTS.get(item), item)); + EFFECTS.keySet().forEach(item -> Registry.register(Registries.STATUS_EFFECT, EFFECTS.get(item), item)); } } diff --git a/src/main/java/ladysnake/ratsmischief/common/init/ModTags.java b/src/main/java/ladysnake/ratsmischief/common/init/ModTags.java new file mode 100644 index 00000000..ecaca0f7 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/common/init/ModTags.java @@ -0,0 +1,15 @@ +package ladysnake.ratsmischief.common.init; + +import ladysnake.ratsmischief.common.RatsMischief; +import net.minecraft.item.Item; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; + +@SuppressWarnings("unused") +public interface ModTags { + TagKey RAT_POUCHES = TagKey.of(RegistryKeys.ITEM, RatsMischief.id("rat_pouches")); + + static void initialize() { + // NO-OP + } +} diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java index 55370e0a..075629e5 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java @@ -1,45 +1,51 @@ package ladysnake.ratsmischief.common.item; +import ladysnake.ratsmischief.client.render.item.RatItemRenderer; import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.entity.RatEntity; import ladysnake.ratsmischief.common.init.ModEntities; +import ladysnake.ratsmischief.mialeemisc.util.MialeeText; import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.client.render.item.BuiltinModelItemRenderer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; +import net.minecraft.registry.Registries; import net.minecraft.text.Text; -import net.minecraft.util.*; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DyeColor; +import net.minecraft.util.Formatting; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import software.bernie.geckolib3.core.IAnimatable; -import software.bernie.geckolib3.core.PlayState; -import software.bernie.geckolib3.core.controller.AnimationController; -import software.bernie.geckolib3.core.event.predicate.AnimationEvent; -import software.bernie.geckolib3.core.manager.AnimationData; -import software.bernie.geckolib3.core.manager.AnimationFactory; -import software.bernie.geckolib3.network.GeckoLibNetwork; -import software.bernie.geckolib3.network.ISyncable; -import software.bernie.geckolib3.util.GeckoLibUtil; -import xyz.amymialee.mialeemisc.util.MialeeText; +import software.bernie.geckolib.animatable.GeoItem; +import software.bernie.geckolib.animatable.SingletonGeoAnimatable; +import software.bernie.geckolib.animatable.client.RenderProvider; +import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; +import software.bernie.geckolib.core.animation.AnimatableManager; +import software.bernie.geckolib.core.animation.AnimationController; +import software.bernie.geckolib.core.object.PlayState; +import software.bernie.geckolib.util.GeckoLibUtil; import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; import static net.minecraft.text.Style.EMPTY; -public class RatItem extends Item implements IAnimatable, ISyncable { - private final AnimationFactory factory = GeckoLibUtil.createFactory(this); +public class RatItem extends Item implements GeoItem { + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); + private final Supplier renderProvider = GeoItem.makeRenderer(this); public RatItem(Settings settings) { super(settings); - GeckoLibNetwork.registerSyncable(this); + SingletonGeoAnimatable.registerSyncedAnimatable(this); } public static void cycleRatReturn(ItemStack stack) { @@ -96,29 +102,40 @@ public static DyeColor getRatColor(ItemStack stack) { return DyeColor.byName(ratColor.toLowerCase(), DyeColor.WHITE); } - private

PlayState predicate(AnimationEvent

event) { - return PlayState.CONTINUE; + @Override + public void createRenderer(Consumer consumer) { + consumer.accept(new RenderProvider() { + private RatItemRenderer renderer; + + @Override + public BuiltinModelItemRenderer getCustomRenderer() { + if (this.renderer == null) + renderer = new RatItemRenderer(); + + return renderer; + } + }); } @Override - public void registerControllers(AnimationData data) { - AnimationController controller = new AnimationController<>(this, "idle", 20, this::predicate); - data.addAnimationController(controller); + public AnimatableInstanceCache getAnimatableInstanceCache() { + return this.cache; } @Override - public AnimationFactory getFactory() { - return this.factory; + public Supplier getRenderProvider() { + return this.renderProvider; } @Override - public void onAnimationSync(int id, int state) { + public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { + controllers.add(new AnimationController<>(this, "idle", 20, state -> PlayState.CONTINUE)); } @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { if (!world.isClient()) { - RatEntity rat = this.getRatFromItem(world, user.getStackInHand(hand), new Vec3d(user.getX(), user.getEyeY() - 0.10000000149011612D, user.getZ()), + RatEntity rat = this.getRatFromItem(world, user.getStackInHand(hand), new Vec3d(user.getX(), user.getEyeY() - 0.1, user.getZ()), hand == Hand.OFF_HAND ? PlayerInventory.OFF_HAND_SLOT : user.getInventory().getSlotWithStack(user.getStackInHand(hand))); if (rat == null) { return TypedActionResult.fail(user.getStackInHand(hand)); @@ -182,8 +199,8 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List too } // potion genes - var potionId = new Identifier(ratTag.getString("PotionGene")); - var statusEffect = Registry.STATUS_EFFECT.get(potionId); + var potionId = Identifier.tryParse(ratTag.getString("PotionGene")); + var statusEffect = Registries.STATUS_EFFECT.get(potionId); if (statusEffect != null) { tooltip.add(Text.translatable("item.ratsmischief.rat.tooltip.potion").setStyle(EMPTY.withColor(Formatting.GRAY)).append(MialeeText.withColor(Text.translatable(statusEffect.getTranslationKey()).setStyle(EMPTY), statusEffect.getColor()))); } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterArmorItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterArmorItem.java index ef80e25c..fed27f4f 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterArmorItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterArmorItem.java @@ -1,6 +1,9 @@ package ladysnake.ratsmischief.common.item; import ladysnake.ratsmischief.client.RatsMischiefClientHelper; +import ladysnake.ratsmischief.common.RatsMischief; +import ladysnake.ratsmischief.mialeemisc.util.MialeeMath; +import ladysnake.ratsmischief.mialeemisc.util.MialeeText; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -13,10 +16,11 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import xyz.amymialee.mialeemisc.util.MialeeMath; -import xyz.amymialee.mialeemisc.util.MialeeText; +import org.quiltmc.loader.api.minecraft.ClientOnly; import java.util.List; import java.util.Set; @@ -24,7 +28,7 @@ public class RatMasterArmorItem extends ArmorItem { public static final Set SLOTS = Set.of(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET); - public RatMasterArmorItem(ArmorMaterial material, EquipmentSlot slot, Settings settings) { + public RatMasterArmorItem(ArmorMaterial material, ArmorSlot slot, Settings settings) { super(material, slot, settings); } @@ -116,17 +120,19 @@ public enum MasterArmorBoost { public static class RatMasterArmorMaterial implements ArmorMaterial { public static final RatMasterArmorMaterial INSTANCE = new RatMasterArmorMaterial(); + private static final String NAME = "rat_master"; + private static final Identifier TEXTURE = RatsMischief.id("textures/models/armor/" + NAME); private static final int[] BASE_DURABILITY = new int[]{13, 15, 16, 11}; private static final int[] PROTECTION_AMOUNTS = new int[]{3, 6, 8, 3}; @Override - public int getDurability(EquipmentSlot slot) { - return BASE_DURABILITY[slot.getEntitySlotId()] * 38; + public int getDurability(ArmorSlot slot) { + return BASE_DURABILITY[slot.getEquipmentSlot().getEntitySlotId()] * 38; } @Override - public int getProtectionAmount(EquipmentSlot slot) { - return PROTECTION_AMOUNTS[slot.getEntitySlotId()]; + public int getProtection(ArmorSlot slot) { + return PROTECTION_AMOUNTS[slot.getEquipmentSlot().getEntitySlotId()]; } @Override @@ -146,7 +152,7 @@ public Ingredient getRepairIngredient() { @Override public String getName() { - return "rat_master"; + return NAME; } @Override @@ -158,5 +164,10 @@ public float getToughness() { public float getKnockbackResistance() { return 0.0f; } + + @Override + public @ClientOnly @NotNull Identifier getTexture() { + return TEXTURE; + } } } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterCloakItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterCloakItem.java index 6e2aef42..1c757125 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterCloakItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterCloakItem.java @@ -1,7 +1,6 @@ package ladysnake.ratsmischief.common.item; import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ArmorMaterial; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -13,7 +12,7 @@ import java.util.List; public class RatMasterCloakItem extends RatMasterArmorItem { - public RatMasterCloakItem(ArmorMaterial material, EquipmentSlot slot, Settings settings) { + public RatMasterCloakItem(ArmorMaterial material, ArmorSlot slot, Settings settings) { super(material, slot, settings); } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterHoodItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterHoodItem.java index 9646f0bd..5cd34d31 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterHoodItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterHoodItem.java @@ -1,7 +1,6 @@ package ladysnake.ratsmischief.common.item; import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ArmorMaterial; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -13,7 +12,7 @@ import java.util.List; public class RatMasterHoodItem extends RatMasterArmorItem { - public RatMasterHoodItem(ArmorMaterial material, EquipmentSlot slot, Settings settings) { + public RatMasterHoodItem(ArmorMaterial material, ArmorSlot slot, Settings settings) { super(material, slot, settings); } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMaskItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMaskItem.java index 109ff769..856748d2 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMaskItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMaskItem.java @@ -1,20 +1,18 @@ package ladysnake.ratsmischief.common.item; -import dev.emi.trinkets.api.SlotReference; -import dev.emi.trinkets.api.TrinketComponent; import dev.emi.trinkets.api.TrinketItem; import dev.emi.trinkets.api.TrinketsApi; +import ladysnake.ratsmischief.common.init.ModItems; +import ladysnake.ratsmischief.mialeemisc.util.MialeeMath; +import ladysnake.ratsmischief.mialeemisc.util.MialeeText; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import xyz.amymialee.mialeemisc.util.MialeeMath; -import xyz.amymialee.mialeemisc.util.MialeeText; import java.util.List; import java.util.Optional; @@ -29,15 +27,14 @@ public static boolean isWearingMask(LivingEntity livingEntity) { } public static ItemStack getWornMask(LivingEntity livingEntity) { - Optional component = TrinketsApi.getTrinketComponent(livingEntity); - if (component.isPresent()) { - for (Pair pair : component.get().getAllEquipped()) { - if (pair.getRight().getItem() instanceof RatMasterMaskItem) { - return pair.getRight(); - } + return TrinketsApi.getTrinketComponent(livingEntity).flatMap(h -> { + var results = h.getEquipped(ModItems.RAT_MASTER_MASK); + if (results.isEmpty()) { + return Optional.empty(); + } else { + return Optional.of(results.get(0).getRight()); } - } - return ItemStack.EMPTY; + }).orElse(ItemStack.EMPTY); } public static int getOffset(ItemStack stack) { diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMirrorItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMirrorItem.java index ea23aadd..3bfd6b69 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMirrorItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterMirrorItem.java @@ -1,23 +1,13 @@ package ladysnake.ratsmischief.common.item; -import ladysnake.ratsmischief.common.entity.RatEntity; -import ladysnake.ratsmischief.common.requiem.RatsMischiefRequiemPlugin; -import ladysnake.requiem.api.v1.possession.PossessionComponent; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import net.minecraft.entity.ai.TargetPredicate; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.math.Box; -import net.minecraft.world.World; public class RatMasterMirrorItem extends Item { public RatMasterMirrorItem(Settings settings) { super(settings); } + /* @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { if (!world.isClient()) { @@ -44,4 +34,5 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han return TypedActionResult.success(user.getStackInHand(hand)); } + */ } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterOcarinaItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterOcarinaItem.java index e501020a..8944b04c 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatMasterOcarinaItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatMasterOcarinaItem.java @@ -5,6 +5,8 @@ import ladysnake.ratsmischief.common.entity.ai.BreedGoal; import ladysnake.ratsmischief.common.entity.ai.DigGoal; import ladysnake.ratsmischief.common.entity.ai.HarvestPlantMealGoal; +import ladysnake.ratsmischief.mialeemisc.items.IClickConsumingItem; +import ladysnake.ratsmischief.mialeemisc.util.MialeeMath; import net.minecraft.block.BlockState; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.ai.goal.Goal; @@ -25,8 +27,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import xyz.amymialee.mialeemisc.items.IClickConsumingItem; -import xyz.amymialee.mialeemisc.util.MialeeMath; import java.util.List; @@ -57,7 +57,7 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han } }); ItemStack stack = user.getStackInHand(hand); - world.playSoundFromEntity(null, user, SoundEvents.BLOCK_NOTE_BLOCK_FLUTE, user.getSoundCategory(), 1f, 0.5f + (stack.getOrCreateNbt().getInt("action") / 4f)); + world.playSoundFromEntity(null, user, SoundEvents.BLOCK_NOTE_BLOCK_FLUTE.value(), user.getSoundCategory(), 1f, 0.5f + (stack.getOrCreateNbt().getInt("action") / 4f)); return TypedActionResult.success(user.getStackInHand(hand)); } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java index 4011f1d1..9bc63a31 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java @@ -3,6 +3,7 @@ import ladysnake.ratsmischief.common.RatsMischief; import ladysnake.ratsmischief.common.entity.RatEntity; import ladysnake.ratsmischief.common.init.ModEntities; +import ladysnake.ratsmischief.mialeemisc.util.MialeeText; import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.Entity; @@ -13,23 +14,23 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; -import static net.minecraft.text.Style.EMPTY; +import net.minecraft.registry.Registries; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import xyz.amymialee.mialeemisc.util.MialeeText; import java.util.List; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; +import static net.minecraft.text.Style.EMPTY; + public class RatPouchItem extends Item { private static final Predicate CLOSEST_RAT_PREDICATE = (ratEntity) -> ratEntity.isTamed(); private final int size; @@ -91,12 +92,12 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { NbtList NbtList = user.getStackInHand(hand).getOrCreateSubNbt(RatsMischief.MOD_ID).getList("rats", NbtElement.COMPOUND_TYPE); - if (NbtList.size() < this.size && entity instanceof RatEntity && ((RatEntity) entity).getOwnerUuid() != null && ((RatEntity) entity).getOwnerUuid().equals(user.getUuid())) { + if (NbtList.size() < this.size && entity instanceof RatEntity rat && rat.getOwnerUuid() != null && rat.getOwnerUuid().equals(user.getUuid())) { NbtCompound NbtCompound = new NbtCompound(); entity.saveNbt(NbtCompound); NbtList.add(NbtCompound); user.getStackInHand(hand).getOrCreateSubNbt(RatsMischief.MOD_ID).put("rats", NbtList); - ((RatEntity) entity).playSpawnEffects(); + rat.playSpawnEffects(); entity.remove(Entity.RemovalReason.DISCARDED); user.getStackInHand(hand).getOrCreateSubNbt(RatsMischief.MOD_ID).putFloat("filled", 1F); @@ -135,8 +136,8 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List too } // potion genes - var potionId = new Identifier(((NbtCompound) ratTag).getString("PotionGene")); - var statusEffect = Registry.STATUS_EFFECT.get(potionId); + var potionId = Identifier.tryParse(((NbtCompound) ratTag).getString("PotionGene")); + var statusEffect = Registries.STATUS_EFFECT.get(potionId); if (statusEffect != null) { text = text.append(" (").append(Text.translatable("item.ratsmischief.rat.tooltip.potion").setStyle(EMPTY.withColor(Formatting.GRAY)).append(MialeeText.withColor(Text.translatable(statusEffect.getTranslationKey()).setStyle(EMPTY), statusEffect.getColor()))).append(")"); } diff --git a/src/main/java/ladysnake/ratsmischief/common/requiem/RatifiedRemnantType.java b/src/main/java/ladysnake/ratsmischief/common/requiem/RatifiedRemnantType.java deleted file mode 100644 index bf4c7986..00000000 --- a/src/main/java/ladysnake/ratsmischief/common/requiem/RatifiedRemnantType.java +++ /dev/null @@ -1,187 +0,0 @@ -package ladysnake.ratsmischief.common.requiem; - -import io.github.ladysnake.pal.AbilitySource; -import io.github.ladysnake.pal.Pal; -import io.github.ladysnake.pal.VanillaAbilities; -import ladysnake.ratsmischief.common.entity.RatEntity; -import ladysnake.ratsmischief.common.init.ModEntities; -import ladysnake.requiem.api.v1.possession.PossessionComponent; -import ladysnake.requiem.api.v1.remnant.MobResurrectable; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import ladysnake.requiem.api.v1.remnant.RemnantState; -import ladysnake.requiem.api.v1.remnant.RemnantType; -import ladysnake.requiem.common.remnant.PlayerBodyTracker; -import ladysnake.requiem.common.remnant.RemnantTypes; -import ladysnake.requiem.core.entity.SoulHolderComponent; -import ladysnake.requiem.core.record.GlobalRecordImpl; -import ladysnake.requiem.core.remnant.MutableRemnantState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.NotNull; - -import java.util.function.Function; - -public class RatifiedRemnantType implements RemnantType { - private final Text name = Text.translatable("ratsmischief:remnant_type.name"); - private final Function stateFactory; - - public RatifiedRemnantType(Function stateFactory) { - this.stateFactory = stateFactory; - } - - @Override - public @NotNull RemnantState create(PlayerEntity player) { - return this.stateFactory.apply(player); - } - - @Override - public boolean isDemon() { - return false; - } - - @Override - public @NotNull Text getName() { - return this.name; - } - - public static class RatifiedRemnantState implements RemnantState { - public static final AbilitySource SOUL_STATE = Pal.getAbilitySource(new Identifier("mischief", "soul_state")); - - private final PlayerEntity player; - private boolean removed; - - public RatifiedRemnantState(PlayerEntity player) { - this.player = player; - } - - @Override - public void setup(RemnantState oldHandler) { - if (!this.player.world.isClient) { - Pal.grantAbility(this.player, VanillaAbilities.INVULNERABLE, SOUL_STATE); - if (this.isInWorld()) { - PossessionComponent.get(this.player).stopPossessing(false); - RatEntity rat = new RatEntity(ModEntities.RAT, this.player.world); - SoulHolderComponent.get(rat).removeSoul(); - rat.copyPositionAndRotation(this.player); - this.player.world.spawnEntity(rat); - PossessionComponent.get(this.player).startPossessing(rat); - } - } - } - - private boolean isInWorld() { - return this.player.world.getEntityById(this.player.getId()) == this.player; - } - - @Override - public void teardown(RemnantState newHandler) { - this.removed = true; - - if (!this.player.world.isClient) { - Pal.revokeAbility(this.player, VanillaAbilities.INVULNERABLE, SOUL_STATE); - if (this.isInWorld()) { - PossessionComponent possessionComponent = PossessionComponent.get(this.player); - MobEntity rat = possessionComponent.getHost(); - - if (rat != null) { - rat.remove(Entity.RemovalReason.DISCARDED); - possessionComponent.stopPossessing(false); - this.player.setHealth(this.player.getHealth()); - } - } - } - } - - @Override - public boolean isIncorporeal() { - return !PossessionComponent.get(this.player).isPossessionOngoing(); - } - - @Override - public boolean isVagrant() { - return !this.removed; - } - - @Override - public boolean setVagrant(boolean vagrant) { - return false; - } - - @Override - public boolean canDissociateFrom(MobEntity possessed) { - return false; // you're in with this rat, forever - } - - @Override - public void prepareRespawn(ServerPlayerEntity original, boolean lossless) { - ((MobResurrectable) this.player).setResurrectionEntity(new RatEntity(ModEntities.RAT, this.player.world)); - } - - @Override - public void serverTick() { - MobEntity possessedEntity = PossessionComponent.get(this.player).getHost(); - if (possessedEntity instanceof RatEntity rat) { - rat.setEating(this.player.isUsingItem()); - } else { // make them respawn on death, or kill them if they're humans - this.player.kill(); // haha get fucked nerd - } - } - } - - public static class SpyingRatRemnantState extends MutableRemnantState { - public SpyingRatRemnantState(PlayerEntity player) { - super(player); - } - - @Override - public void teardown(RemnantState newHandler) { - super.teardown(newHandler); - // Absolutely massive brain fix for the requiem bug where damage effects display after the player merged with their shell - // FIXME Must be removed after it's been properly fixed upstream - PlayerBodyTracker.get(this.player).setAnchor(new GlobalRecordImpl(null, null)); - } - - @Override - public boolean canDissociateFrom(MobEntity possessed) { - return false; // we use a custom fracture handler for dissociation - } - - @Override - public boolean canSplit(boolean forced) { - // Allow splitting so that the mirror can work as intended - return true; - } - - @Override - public void prepareRespawn(ServerPlayerEntity original, boolean lossless) { - this.setVagrant(true); - } - - @Override - protected void regenerateBody(LivingEntity body) { - throw new UnsupportedOperationException(); - } - - @Override - protected void onRespawnAfterDeath() { - // NO-OP - } - - @Override - public void serverTick() { - MobEntity possessedEntity = PossessionComponent.get(this.player).getHost(); - if (possessedEntity instanceof RatEntity rat) { - rat.setEating(this.player.isUsingItem()); - } else if (!this.isVagrant()) { - RemnantComponent.get(this.player).become(RemnantTypes.MORTAL); - } else { - RatsMischiefRequiemPlugin.goBackToBody((ServerPlayerEntity) this.player); - } - } - } -} diff --git a/src/main/java/ladysnake/ratsmischief/common/requiem/RatsMischiefRequiemPlugin.java b/src/main/java/ladysnake/ratsmischief/common/requiem/RatsMischiefRequiemPlugin.java deleted file mode 100644 index 16d5cb77..00000000 --- a/src/main/java/ladysnake/ratsmischief/common/requiem/RatsMischiefRequiemPlugin.java +++ /dev/null @@ -1,73 +0,0 @@ -package ladysnake.ratsmischief.common.requiem; - -import ladysnake.ratsmischief.common.entity.RatEntity; -import ladysnake.requiem.api.v1.RequiemPlugin; -import ladysnake.requiem.api.v1.event.requiem.HumanityCheckCallback; -import ladysnake.requiem.api.v1.event.requiem.InitiateFractureCallback; -import ladysnake.requiem.api.v1.event.requiem.PossessionStartCallback; -import ladysnake.requiem.api.v1.possession.PossessionComponent; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import ladysnake.requiem.api.v1.remnant.RemnantType; -import ladysnake.requiem.common.RequiemRecordTypes; -import ladysnake.requiem.common.entity.PlayerShellEntity; -import ladysnake.requiem.common.remnant.PlayerBodyTracker; -import ladysnake.requiem.common.remnant.RemnantTypes; -import net.minecraft.entity.Entity; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import org.jetbrains.annotations.Nullable; - -public class RatsMischiefRequiemPlugin implements RequiemPlugin { - public static final RatifiedRemnantType RATIFIED_REMNANT_TYPE = new RatifiedRemnantType(RatifiedRemnantType.RatifiedRemnantState::new); - public static final RatifiedRemnantType SPYING_RAT_REMNANT_TYPE = new RatifiedRemnantType(RatifiedRemnantType.SpyingRatRemnantState::new); - - public static boolean goBackToBody(ServerPlayerEntity player) { - if (getBody(player) instanceof PlayerShellEntity body) { - PossessionComponent.get(player).stopPossessing(true); - RemnantComponent.get(player).merge(body); - RemnantComponent.get(player).become(RemnantTypes.MORTAL); - return true; - } - return false; - } - - @Nullable - private static Entity getBody(ServerPlayerEntity player) { - return PlayerBodyTracker.get(player).getAnchor() - .flatMap(a -> a.get(RequiemRecordTypes.ENTITY_REF)) - .flatMap(ptr -> ptr.resolve(player.server)).orElse(null); - } - - @Override - public void onRequiemInitialize() { - // always allow rat possession for rat players - PossessionStartCallback.EVENT.register(new Identifier("ratsmischief:possession"), (mobEntity, playerEntity, b) -> { - RemnantType remnantType = RemnantComponent.get(playerEntity).getRemnantType(); - if (mobEntity instanceof RatEntity && remnantType == RATIFIED_REMNANT_TYPE || remnantType == SPYING_RAT_REMNANT_TYPE) { - return PossessionStartCallback.Result.ALLOW; - } - return PossessionStartCallback.Result.PASS; - }); - - InitiateFractureCallback.EVENT.register(player -> { - if (RemnantComponent.get(player).getRemnantType() == SPYING_RAT_REMNANT_TYPE) { - return goBackToBody(player); - } - return false; - }); - - HumanityCheckCallback.EVENT.register(livingEntity -> { - if (livingEntity instanceof RatEntity) { - return 2; - } - return 0; - }); - } - - @Override - public void registerRemnantStates(Registry registry) { - Registry.register(registry, new Identifier("ratsmischief:ratified"), RATIFIED_REMNANT_TYPE); - Registry.register(registry, new Identifier("ratsmischief:spying_rat"), SPYING_RAT_REMNANT_TYPE); - } -} diff --git a/src/main/java/ladysnake/ratsmischief/common/util/PlayerRatOwner.java b/src/main/java/ladysnake/ratsmischief/common/util/PlayerRatOwner.java index 6b6fa11a..0d1d4dc3 100644 --- a/src/main/java/ladysnake/ratsmischief/common/util/PlayerRatOwner.java +++ b/src/main/java/ladysnake/ratsmischief/common/util/PlayerRatOwner.java @@ -1,7 +1,7 @@ package ladysnake.ratsmischief.common.util; public interface PlayerRatOwner { - boolean shouldBringItems(); + boolean mischief$shouldBringItems(); - void setBringingItems(boolean bringingItems); + void mischief$setBringingItems(boolean bringingItems); } diff --git a/src/main/java/ladysnake/ratsmischief/common/world/RatSpawner.java b/src/main/java/ladysnake/ratsmischief/common/world/RatSpawner.java index 7a4c9904..114b6a07 100644 --- a/src/main/java/ladysnake/ratsmischief/common/world/RatSpawner.java +++ b/src/main/java/ladysnake/ratsmischief/common/world/RatSpawner.java @@ -60,7 +60,6 @@ public int spawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals) } private int spawnInHouse(ServerWorld world, BlockPos pos) { - boolean i = true; if (world.getPointOfInterestStorage().count((registryEntry) -> registryEntry.isRegistryKey(PointOfInterestTypes.HOME), pos, 48, PointOfInterestStorage.OccupationStatus.HAS_SPACE) > 4L) { List list = world.getNonSpectatingEntities(RatEntity.class, (new Box(pos)).expand(48.0D, 8.0D, 48.0D)); if (list.size() < 10) { diff --git a/src/main/java/ladysnake/ratsmischief/mialeemisc/MialeeMisc.java b/src/main/java/ladysnake/ratsmischief/mialeemisc/MialeeMisc.java new file mode 100644 index 00000000..5adb499a --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mialeemisc/MialeeMisc.java @@ -0,0 +1,18 @@ +package ladysnake.ratsmischief.mialeemisc; + +import ladysnake.ratsmischief.common.RatsMischief; +import ladysnake.ratsmischief.mialeemisc.items.IClickConsumingItem; +import net.minecraft.util.Identifier; +import org.quiltmc.qsl.networking.api.ServerPlayNetworking; + +public class MialeeMisc { + public static final Identifier clickConsumePacket = RatsMischief.id("click_consume"); + + public static void onInitialize() { + ServerPlayNetworking.registerGlobalReceiver(clickConsumePacket, (minecraftServer, serverPlayer, serverPlayNetworkHandler, packetByteBuf, packetSender) -> minecraftServer.execute(() -> { + if (serverPlayer.getMainHandStack().getItem() instanceof IClickConsumingItem item) { + item.mialeeMisc$doAttack(serverPlayer); + } + })); + } +} diff --git a/src/main/java/ladysnake/ratsmischief/mialeemisc/items/IClickConsumingItem.java b/src/main/java/ladysnake/ratsmischief/mialeemisc/items/IClickConsumingItem.java new file mode 100644 index 00000000..90fc9ad3 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mialeemisc/items/IClickConsumingItem.java @@ -0,0 +1,7 @@ +package ladysnake.ratsmischief.mialeemisc.items; + +import net.minecraft.server.network.ServerPlayerEntity; + +public interface IClickConsumingItem { + void mialeeMisc$doAttack(ServerPlayerEntity player); +} diff --git a/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeMath.java b/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeMath.java new file mode 100644 index 00000000..43448d25 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeMath.java @@ -0,0 +1,63 @@ +package ladysnake.ratsmischief.mialeemisc.util; + +public class MialeeMath { + /** + * Clamps a value to a range, looping around if the value is outside the range. + * Inclusive of the min and exclusive of the max values. + * Only works for ints. + */ + public static int clampLoop(int input, int start, int end) { + if (start - end == 0) { + return start; + } + if (end < start) { + int temp = start; + start = end; + end = temp; + } + if (input < start) { + return end - ((start - input) % (end - start)); + } + return start + ((input - start) % (end - start)); + } + + /** + * Clamps a value to a range, looping around if the value is outside the range. + * Inclusive of the min and exclusive of the max values. + * Use floats instead of ints. + */ + public static float clampLoop(float input, float start, float end) { + if (start - end == 0) { + return start; + } + if (end < start) { + float temp = start; + start = end; + end = temp; + } + if (input < start) { + return end - ((start - input) % (end - start)); + } + return start + ((input - start) % (end - start)); + } + + /** + * Clamps a value to a range, looping around if the value is outside the range. + * Inclusive of the min and exclusive of the max values. + * Use doubles instead of ints. + */ + public static double clampLoop(double input, double start, double end) { + if (start - end == 0) { + return start; + } + if (end < start) { + double temp = start; + start = end; + end = temp; + } + if (input < start) { + return end - ((start - input) % (end - start)); + } + return start + ((input - start) % (end - start)); + } +} diff --git a/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeText.java b/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeText.java new file mode 100644 index 00000000..4f0c1527 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mialeemisc/util/MialeeText.java @@ -0,0 +1,33 @@ +package ladysnake.ratsmischief.mialeemisc.util; + +import net.minecraft.text.Style; +import net.minecraft.text.Text; + +import java.util.List; + +public class MialeeText { + /** + * Takes a text and returns the same text but with the given int color. + */ + public static Text withColor(Text text, int color) { + Style style = text.getStyle().withColor(color); + List styled = text.setStyle(style); + if (!styled.isEmpty()) { + return styled.get(0); + } + //MialeeMisc.LOGGER.error("Failed to set color of text: " + text.getString() + " to color: " + color); + return text; + } + + /** + * Takes a text and returns the same text but with without italics. + */ + public static Text withoutItalics(Text text) { + List styled = text.setStyle(text.getStyle().withItalic(false)); + if (!styled.isEmpty()) { + return styled.get(0); + } + //MialeeMisc.LOGGER.error("Failed to remove italics from text: " + text.getString()); + return text; + } +} diff --git a/src/main/java/ladysnake/ratsmischief/mixin/EnchantmentHelperMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/EnchantmentHelperMixin.java index 70598483..459794a3 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/EnchantmentHelperMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/EnchantmentHelperMixin.java @@ -10,10 +10,12 @@ import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @Mixin(EnchantmentHelper.class) public class EnchantmentHelperMixin { + @Unique private static Enchantment storedEnchantment; @WrapOperation(method = "getPossibleEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/Enchantment;isAvailableForRandomSelection()Z")) diff --git a/src/main/java/ladysnake/ratsmischief/mixin/FollowTargetGoalMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/FollowTargetGoalMixin.java index 7f26d661..5e7fb6f0 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/FollowTargetGoalMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/FollowTargetGoalMixin.java @@ -1,4 +1,4 @@ -package ladysnake.ratsmischief.mixin;// +//package ladysnake.ratsmischief.mixin; ///* // * Requiem // * Copyright (C) 2017-2021 Ladysnake diff --git a/src/main/java/ladysnake/ratsmischief/mixin/ItemEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/ItemEntityMixin.java index cb896f2f..f1284697 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/ItemEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/ItemEntityMixin.java @@ -31,14 +31,14 @@ public void tick(CallbackInfo ci) { ItemStack stack = this.getStack(); if (stack.isOf(ModItems.RAT)) { - if (!this.world.isClient()) { - NbtCompound ratTag = RatItem.getRatTag(stack, this.world); - RatEntity rat = ModEntities.RAT.create(this.world); + if (!this.getWorld().isClient) { + NbtCompound ratTag = RatItem.getRatTag(stack, this.getWorld()); + RatEntity rat = ModEntities.RAT.create(this.getWorld()); if (rat != null) { rat.readNbt(ratTag); rat.updatePosition(this.getX(), this.getY(), this.getZ()); rat.setPos(this.getX(), this.getY(), this.getZ()); - this.world.spawnEntity(rat); + this.getWorld().spawnEntity(rat); rat.setSitting(false); stack.decrement(1); ci.cancel(); diff --git a/src/main/java/ladysnake/ratsmischief/mixin/LivingEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/LivingEntityMixin.java index 4c814c81..e8899fd8 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/LivingEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/LivingEntityMixin.java @@ -5,7 +5,6 @@ import ladysnake.ratsmischief.common.entity.RatEntity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.damage.EntityDamageSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -24,10 +23,8 @@ public abstract class LivingEntityMixin { @WrapOperation(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;takeKnockback(DDD)V")) private void mischief$lessKnockback(LivingEntity entity, double x, double y, double z, Operation operation) { - if (this.lastSource instanceof EntityDamageSource entityDamageSource) { - if (entityDamageSource.getAttacker() instanceof RatEntity) { - return; - } + if (this.lastSource.getAttacker() instanceof RatEntity) { + return; } operation.call(entity, x, y, z); } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/PlayerEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/PlayerEntityMixin.java index 682fdbea..38a90248 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/PlayerEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/PlayerEntityMixin.java @@ -47,12 +47,12 @@ protected PlayerEntityMixin(EntityType entityType, World } @Override - public boolean shouldBringItems() { + public boolean mischief$shouldBringItems() { return this.shouldRatsBringItems; } @Override - public void setBringingItems(boolean bringingItems) { + public void mischief$setBringingItems(boolean bringingItems) { this.shouldRatsBringItems = bringingItems; } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/ScreenHandlerMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/ScreenHandlerMixin.java index 69d4d63b..c443f637 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/ScreenHandlerMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/ScreenHandlerMixin.java @@ -1,5 +1,6 @@ package ladysnake.ratsmischief.mixin; +import ladysnake.ratsmischief.common.init.ModItems; import ladysnake.ratsmischief.common.init.ModSoundEvents; import ladysnake.ratsmischief.common.item.RatItem; import ladysnake.ratsmischief.common.item.RatMasterArmorItem; @@ -45,13 +46,13 @@ public class ScreenHandlerMixin { player.playSound(ModSoundEvents.ITEM_RAT_TOGGLE, SoundCategory.PLAYERS, 0.9f, 1.5f); ci.cancel(); } - } else if (stack.getItem() instanceof RatMasterMaskItem) { + } else if (stack.isOf(ModItems.RAT_MASTER_MASK)) { RatMasterMaskItem.incrementOffset(stack); player.playSound(ModSoundEvents.ITEM_RAT_TOGGLE, SoundCategory.PLAYERS, 0.9f, 1.5f); ci.cancel(); } else if (stack.getItem() instanceof RatMasterOcarinaItem) { if (player instanceof PlayerRatOwner playerRatOwner) { - playerRatOwner.setBringingItems(!playerRatOwner.shouldBringItems()); + playerRatOwner.mischief$setBringingItems(!playerRatOwner.mischief$shouldBringItems()); player.playSound(ModSoundEvents.ITEM_RAT_TOGGLE, SoundCategory.PLAYERS, 0.9f, 1.5f); ci.cancel(); } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/SculkSensorBlockEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/SculkSensorBlockEntityMixin.java index f9951741..ef63bc79 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/SculkSensorBlockEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/SculkSensorBlockEntityMixin.java @@ -1,21 +1,19 @@ package ladysnake.ratsmischief.mixin; import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.block.entity.SculkSensorBlockEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.event.GameEvent; -import net.minecraft.world.event.listener.GameEventListener; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(SculkSensorBlockEntity.class) +@Mixin(targets = "net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback") public class SculkSensorBlockEntityMixin { @Inject(method = "accepts", at = @At(value = "HEAD"), cancellable = true) - private void mischief$noRats(ServerWorld world, GameEventListener listener, BlockPos pos, GameEvent event, GameEvent.Context context, CallbackInfoReturnable cir) { - if (context.sourceEntity() instanceof RatEntity) { + private void mischief$noRats(ServerWorld world, BlockPos pos, GameEvent event, GameEvent.Context eventContext, CallbackInfoReturnable cir) { + if (eventContext.sourceEntity() instanceof RatEntity) { cir.setReturnValue(false); } } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/SculkShriekerBlockEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/SculkShriekerBlockEntityMixin.java index 308e3d49..d726197a 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/SculkShriekerBlockEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/SculkShriekerBlockEntityMixin.java @@ -1,21 +1,19 @@ package ladysnake.ratsmischief.mixin; import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.block.entity.SculkSensorBlockEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.event.GameEvent; -import net.minecraft.world.event.listener.GameEventListener; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(SculkSensorBlockEntity.class) +@Mixin(targets = "net/minecraft/block/entity/SculkShriekerBlockEntity$VibrationCallback") public class SculkShriekerBlockEntityMixin { @Inject(method = "accepts", at = @At(value = "HEAD"), cancellable = true) - private void mischief$noRats(ServerWorld world, GameEventListener listener, BlockPos pos, GameEvent event, GameEvent.Context context, CallbackInfoReturnable cir) { - if (context.sourceEntity() instanceof RatEntity) { + private void mischief$noRats(ServerWorld world, BlockPos pos, GameEvent event, GameEvent.Context eventContext, CallbackInfoReturnable cir) { + if (eventContext.sourceEntity() instanceof RatEntity) { cir.setReturnValue(false); } } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/WardenEntityMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/WardenEntityMixin.java index fb56168d..e06c9887 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/WardenEntityMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/WardenEntityMixin.java @@ -1,21 +1,19 @@ package ladysnake.ratsmischief.mixin; import ladysnake.ratsmischief.common.entity.RatEntity; -import net.minecraft.entity.mob.warden.WardenEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.event.GameEvent; -import net.minecraft.world.event.listener.GameEventListener; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(WardenEntity.class) +@Mixin(targets = "net/minecraft/entity/mob/warden/WardenEntity$C_xfllwcxz") public class WardenEntityMixin { @Inject(method = "accepts", at = @At(value = "HEAD"), cancellable = true) - private void mischief$noRats(ServerWorld world, GameEventListener listener, BlockPos pos, GameEvent event, GameEvent.Context context, CallbackInfoReturnable cir) { - if (context.sourceEntity() instanceof RatEntity) { + private void mischief$noRats(ServerWorld world, BlockPos pos, GameEvent event, GameEvent.Context eventContext, CallbackInfoReturnable cir) { + if (eventContext.sourceEntity() instanceof RatEntity) { cir.setReturnValue(false); } } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/client/ArmorFeatureRendererMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/client/ArmorFeatureRendererMixin.java index 68aff35e..de38323a 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/client/ArmorFeatureRendererMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/client/ArmorFeatureRendererMixin.java @@ -18,6 +18,7 @@ import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.render.entity.model.PlayerEntityModel; import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModelManager; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -50,13 +51,13 @@ public ArmorFeatureRendererMixin(FeatureRendererContext context) { } @Inject(method = "", at = @At("TAIL")) - private void mischief$init(FeatureRendererContext context, A leggingsModel, A bodyModel, CallbackInfo ci) { + private void mischief$init(FeatureRendererContext context, A leggingsModel, A bodyModel, BakedModelManager modelManager, CallbackInfo ci) { if (context instanceof EntityRendererWrapper wrapper) { if (context instanceof PlayerEntityRendererWrapper playerWrapper) { this.slim = playerWrapper.mischief$isSlim(); } - this.leggingsModel = new PlayerEntityModel<>(wrapper.getContext().getPart(RatsMischiefClient.RAT_MASTER_ARMOR_INNER_LAYER), false); - this.playerModel = new PlayerEntityModel<>(wrapper.getContext().getPart(this.slim ? RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER_SLIM : RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER), this.slim); + this.leggingsModel = new PlayerEntityModel<>(wrapper.mischief$getContext().getPart(RatsMischiefClient.RAT_MASTER_ARMOR_INNER_LAYER), this.slim); + this.playerModel = new PlayerEntityModel<>(wrapper.mischief$getContext().getPart(this.slim ? RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER_SLIM : RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER), this.slim); } } @@ -74,7 +75,7 @@ private void renderRatArmor(MatrixStack matrices, VertexConsumerProvider vertexC ItemStack itemStack = entity.getEquippedStack(armorSlot); if (itemStack.getItem() instanceof RatMasterArmorItem armorItem) { PlayerEntityModel armorModel = this.getRatModel(armorSlot); - if (armorItem.getSlotType() == armorSlot) { + if (armorItem.getPreferredSlot() == armorSlot) { { armorModel.handSwingProgress = this.getContextModel().handSwingProgress; armorModel.riding = this.getContextModel().riding; @@ -186,7 +187,7 @@ private boolean usesRatSecondLayer(EquipmentSlot slot) { @Unique private Identifier getRatArmorTexture(ArmorItem item, boolean legs) { - String string = "textures/entity/armor/" + item.getMaterial().getName() + "_layer_" + (legs ? 2 : this.slim ? "1_slim" : 1) + ".png"; + String string = "textures/models/armor/" + item.getMaterial().getName() + "_layer_" + (legs ? 2 : this.slim ? "1_slim" : 1) + ".png"; if (this.slim) { return SLIM_ARMOR_TEXTURE_CACHE.computeIfAbsent(string, RatsMischief::id); } else { diff --git a/src/main/java/ladysnake/ratsmischief/mixin/client/HeadFeatureRendererMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/client/HeadFeatureRendererMixin.java index 52da9b10..339ed0ad 100644 --- a/src/main/java/ladysnake/ratsmischief/mixin/client/HeadFeatureRendererMixin.java +++ b/src/main/java/ladysnake/ratsmischief/mixin/client/HeadFeatureRendererMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import ladysnake.ratsmischief.common.init.ModItems; import ladysnake.ratsmischief.common.item.RatMasterMaskItem; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.feature.HeadFeatureRenderer; @@ -25,9 +26,9 @@ public class HeadFeatureRendererMixin { return original.call(entity, slot); } - @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT) + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"), locals = LocalCapture.CAPTURE_FAILSOFT) private void amarite$maskOffset(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci, ItemStack stack) { - if (stack.getItem() instanceof RatMasterMaskItem) { + if (stack.isOf(ModItems.RAT_MASTER_MASK)) { matrixStack.translate(0, RatMasterMaskItem.getOffset(stack) * 0.1, 0); } } diff --git a/src/main/java/ladysnake/ratsmischief/mixin/compat/PlayerBodyTrackerMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/compat/PlayerBodyTrackerMixin.java deleted file mode 100644 index b0c9f77a..00000000 --- a/src/main/java/ladysnake/ratsmischief/mixin/compat/PlayerBodyTrackerMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package ladysnake.ratsmischief.mixin.compat; - -import ladysnake.ratsmischief.common.requiem.RatsMischiefRequiemPlugin; -import ladysnake.requiem.api.v1.record.GlobalRecord; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import ladysnake.requiem.common.remnant.PlayerBodyTracker; -import ladysnake.requiem.common.remnant.RemnantTypes; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.network.ServerPlayerEntity; -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(PlayerBodyTracker.class) -public class PlayerBodyTrackerMixin { - @Shadow - @Final - private PlayerEntity player; - - @Inject(method = "updateBodyHealth", at = @At(value = "INVOKE", target = "Lladysnake/requiem/common/network/RequiemNetworking;sendAnchorDamageMessage(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V", shift = At.Shift.AFTER)) - private void getBackToBody(GlobalRecord anchor, CallbackInfo ci) { - if (RemnantComponent.get(this.player).getRemnantType() == RatsMischiefRequiemPlugin.SPYING_RAT_REMNANT_TYPE) { - RatsMischiefRequiemPlugin.goBackToBody((ServerPlayerEntity) this.player); - } - } - - @Inject(method = "onBodyDisappeared", at = @At(value = "FIELD", target = "Lladysnake/requiem/common/remnant/PlayerBodyTracker;previousAnchorHealth:F", shift = At.Shift.AFTER), remap = false) - private void reset(CallbackInfo ci) { - if (RemnantComponent.get(this.player).getRemnantType() == RatsMischiefRequiemPlugin.SPYING_RAT_REMNANT_TYPE) { - RemnantComponent.get(this.player).become(RemnantTypes.MORTAL); - this.player.kill(); - } - } -} diff --git a/src/main/java/ladysnake/ratsmischief/mixin/compat/VanillaRequiemPluginMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/compat/VanillaRequiemPluginMixin.java deleted file mode 100644 index 84cb8ec1..00000000 --- a/src/main/java/ladysnake/ratsmischief/mixin/compat/VanillaRequiemPluginMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package ladysnake.ratsmischief.mixin.compat; - -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import ladysnake.ratsmischief.common.requiem.RatsMischiefRequiemPlugin; -import ladysnake.requiem.api.v1.remnant.RemnantComponent; -import ladysnake.requiem.common.VanillaRequiemPlugin; -import net.minecraft.entity.player.PlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(VanillaRequiemPlugin.class) -public class VanillaRequiemPluginMixin { - @ModifyExpressionValue(method = "refreshInventoryLocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;isIn(Lnet/minecraft/tag/TagKey;)Z")) - private boolean allowMainInventory(boolean allow, PlayerEntity player) { - if (RemnantComponent.get(player).getRemnantType() == RatsMischiefRequiemPlugin.RATIFIED_REMNANT_TYPE) { - return true; - } - - return allow; - } -} diff --git a/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/ItemRendererMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/ItemRendererMixin.java new file mode 100644 index 00000000..ca564826 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/ItemRendererMixin.java @@ -0,0 +1,34 @@ +package ladysnake.ratsmischief.mixin.mialeemisc.client; + +import ladysnake.ratsmischief.common.init.ModItems; +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.util.ModelIdentifier; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +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.CallbackInfoReturnable; + +@Mixin(ItemRenderer.class) +public abstract class ItemRendererMixin { + + @Shadow @Final private ItemModels models; + + @Inject(method = "getHeldItemModel", at = @At("HEAD"), cancellable = true) + private void mialeeMisc$heldItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable cir) { + if (ModItems.RAT_MASTER_MASK.equals(stack.getItem())) { + var bakedModel = this.models.getModelManager().getModel(new ModelIdentifier(new Identifier("minecraft:trident_in_hand"), "inventory")); + var clientWorld = world instanceof ClientWorld ? (ClientWorld) world : null; + var bakedModel2 = bakedModel.getOverrides().apply(bakedModel, stack, clientWorld, entity, seed); + cir.setReturnValue(bakedModel2 == null ? this.models.getModelManager().getMissingModel() : bakedModel2); + } + } +} diff --git a/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/MinecraftClientMixin.java b/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/MinecraftClientMixin.java new file mode 100644 index 00000000..44612573 --- /dev/null +++ b/src/main/java/ladysnake/ratsmischief/mixin/mialeemisc/client/MinecraftClientMixin.java @@ -0,0 +1,30 @@ +package ladysnake.ratsmischief.mixin.mialeemisc.client; + +import ladysnake.ratsmischief.mialeemisc.MialeeMisc; +import ladysnake.ratsmischief.mialeemisc.items.IClickConsumingItem; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import org.jetbrains.annotations.Nullable; +import org.quiltmc.qsl.networking.api.PacketByteBufs; +import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; +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.CallbackInfoReturnable; + +@Mixin(MinecraftClient.class) +public class MinecraftClientMixin { + @Shadow @Nullable public ClientPlayerEntity player; + + @Inject(method = "doAttack", at = @At("HEAD"), cancellable = true) + private void mialeeMisc$cancelAttack(CallbackInfoReturnable cir) { + if (this.player != null) { + if (this.player.getMainHandStack().getItem() instanceof IClickConsumingItem) { + ClientPlayNetworking.send(MialeeMisc.clickConsumePacket, PacketByteBufs.empty()); + cir.setReturnValue(false); + } + } + } + +} diff --git a/src/main/resources/assets/ratsmischief/models/item/rat_master_mask_worn.json b/src/main/resources/assets/ratsmischief/models/item/rat_master_mask_worn.json index 2a6a0aba..3a4895f5 100644 --- a/src/main/resources/assets/ratsmischief/models/item/rat_master_mask_worn.json +++ b/src/main/resources/assets/ratsmischief/models/item/rat_master_mask_worn.json @@ -2,7 +2,7 @@ "credit": "Made with Blockbench", "texture_size": [32, 32], "textures": { - "1": "ratsmischief:entity/armor/rat_master_mask" + "1": "ratsmischief:models/armor/rat_master_mask" }, "elements": [ { diff --git a/src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_1.png b/src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_1.png similarity index 100% rename from src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_1.png rename to src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_1.png diff --git a/src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_1_slim.png b/src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_1_slim.png similarity index 100% rename from src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_1_slim.png rename to src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_1_slim.png diff --git a/src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_2.png b/src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_2.png similarity index 100% rename from src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_layer_2.png rename to src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_layer_2.png diff --git a/src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_mask.png b/src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_mask.png similarity index 100% rename from src/main/resources/assets/ratsmischief/textures/entity/armor/rat_master_mask.png rename to src/main/resources/assets/ratsmischief/textures/models/armor/rat_master_mask.png diff --git a/src/main/resources/data/ratsmischief/damage_type/rat.json b/src/main/resources/data/ratsmischief/damage_type/rat.json new file mode 100644 index 00000000..712cd536 --- /dev/null +++ b/src/main/resources/data/ratsmischief/damage_type/rat.json @@ -0,0 +1,5 @@ +{ + "exhaustion": 0.1, + "message_id": "rat", + "scaling": "when_caused_by_living_non_player" +} diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_breeches_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_breeches_smithing.json index 92accc87..f3b79fa0 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_breeches_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_breeches_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_breeches" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_cloak_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_cloak_smithing.json index c29faf27..3177ba74 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_cloak_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_cloak_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_cloak" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_greaves_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_greaves_smithing.json index dbc690a4..b119f673 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_greaves_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_greaves_smithing.json @@ -1,6 +1,6 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -9,5 +9,6 @@ }, "result": { "item": "ratsmischief:rat_master_greaves" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_hood_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_hood_smithing.json index 90b710bc..20d9a31c 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_hood_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_hood_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_hood" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_skeleton_skull_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_skeleton_skull_smithing.json index a05d7251..1e443c78 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_skeleton_skull_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_skeleton_skull_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_mask" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_wither_skeleton_skull_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_wither_skeleton_skull_smithing.json index 4fceded1..2ac16136 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_wither_skeleton_skull_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_mask_from_wither_skeleton_skull_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_mask" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_mirror_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_mirror_smithing.json index 33670b3a..1f4e4697 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_mirror_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_mirror_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_mirror" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_ocarina_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_ocarina_smithing.json index 8996765b..a11cd560 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_ocarina_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_ocarina_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_ocarina" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/recipes/rat_master_pouch_smithing.json b/src/main/resources/data/ratsmischief/recipes/rat_master_pouch_smithing.json index 1a2f4c37..df13172a 100644 --- a/src/main/resources/data/ratsmischief/recipes/rat_master_pouch_smithing.json +++ b/src/main/resources/data/ratsmischief/recipes/rat_master_pouch_smithing.json @@ -1,5 +1,5 @@ { - "type": "minecraft:smithing", + "type": "minecraft:smithing_transform", "addition": { "item": "ratsmischief:clothed_ingot" }, @@ -8,5 +8,6 @@ }, "result": { "item": "ratsmischief:rat_master_pouch" - } + }, + "template": [] } diff --git a/src/main/resources/data/ratsmischief/tags/items/rat_pouches.json b/src/main/resources/data/ratsmischief/tags/items/rat_pouches.json new file mode 100644 index 00000000..78bcd190 --- /dev/null +++ b/src/main/resources/data/ratsmischief/tags/items/rat_pouches.json @@ -0,0 +1,9 @@ +{ + "replace": false, + "values": [ + "ratsmischief:leather_rat_pouch", + "ratsmischief:twisted_rat_pouch", + "ratsmischief:purpur_rat_pouch", + "ratsmischief:rat_master_pouch" + ] +} diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json index 227d04d8..1b34218c 100644 --- a/src/main/resources/quilt.mod.json +++ b/src/main/resources/quilt.mod.json @@ -24,23 +24,16 @@ }, "depends": [ { - "id": "quilted_fabric_api" + "id": "quilted_fabric_api", + "versions": "*" }, { - "id": "geckolib3" + "id": "geckolib", + "versions": "*" }, { - "id": "trinkets" - }, - { - "id": "mialeemisc" - }, - { - "id": "step-height-entity-attribute" - }, - { - "id": "requiem", - "unless": "requiem-lite" + "id": "trinkets", + "versions": "*" } ] }, diff --git a/src/main/resources/ratsmischief.mixins.json b/src/main/resources/ratsmischief.mixins.json index fcbd298b..1e6b6bed 100644 --- a/src/main/resources/ratsmischief.mixins.json +++ b/src/main/resources/ratsmischief.mixins.json @@ -13,9 +13,7 @@ "ScreenHandlerMixin", "SculkSensorBlockEntityMixin", "SculkShriekerBlockEntityMixin", - "WardenEntityMixin", - "compat.PlayerBodyTrackerMixin", - "compat.VanillaRequiemPluginMixin" + "WardenEntityMixin" ], "client": [ "client.ArmorFeatureRendererMixin", @@ -24,7 +22,9 @@ "client.HeadFeatureRendererMixin", "client.HeldItemRendererMixin", "client.ItemEntityRendererMixin", - "client.PlayerEntityRendererMixin" + "client.PlayerEntityRendererMixin", + "mialeemisc.client.ItemRendererMixin", + "mialeemisc.client.MinecraftClientMixin" ], "injectors": { "defaultRequire": 1