Skip to content

Commit

Permalink
fix: player init bug by mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
gloridifice committed Jun 17, 2024
1 parent 7d8d64c commit 423f2fa
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 126 deletions.
153 changes: 82 additions & 71 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "2.0.0"
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0'

id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "2.0.0"
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0'
// id 'com.github.johnrengelman.shadow' version '8.1.1'
}

version = project.mod_version + "+" + project.mc_version + "-fabric" + "-" + project.build_state
group = project.maven_group

base {
archivesName = project.archives_base_name
archivesName = project.archives_base_name
}

repositories {
maven {
name = 'Xander Maven'
url = 'https://maven.isxander.dev/releases'
}
maven {
// location of the maven that hosts JEI files before January 2023
name = "Progwml6's maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of the maven that hosts JEI files since January 2023
name = "Jared's maven"
url = "https://maven.blamejared.com/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.dev"
}
maven {
name = 'Xander Maven'
url = 'https://maven.isxander.dev/releases'
}
maven {
// location of the maven that hosts JEI files before January 2023
name = "Progwml6's maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of the maven that hosts JEI files since January 2023
name = "Jared's maven"
url = "https://maven.blamejared.com/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.dev"
}
}

loom {
splitEnvironmentSourceSets()

mods {
"watersource" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
mods {
"watersource" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}

fabricApi {
configureDataGeneration()
configureDataGeneration()
}

//shadowJar {
// configurations = [project.configurations.shadow] exclude("META-INF")
//}

dependencies {
minecraft "com.mojang:minecraft:${project.mc_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'
minecraft "com.mojang:minecraft:${project.mc_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"

// toml
implementation 'com.akuleshov7:ktoml-core:0.5.1'
implementation 'com.akuleshov7:ktoml-file:0.5.1'
// toml
include(implementation('com.akuleshov7:ktoml-core-jvm:0.5.1'))
include(implementation('com.akuleshov7:ktoml-file-jvm:0.5.1'))

// // compile against the JEI API but do not include it at runtime
// modCompileOnlyApi("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
Expand All @@ -71,53 +75,60 @@ dependencies {
// modRuntimeOnly("mezz.jei:jei-${mc_version}-fabric:${jei_version}")
}

remapJar {
// nestedJars.from('com.akuleshov7:ktoml-core:0.5.1')
addNestedDependencies = true
// include())
// include(implementation('com.akuleshov7:ktoml-file:0.5.1'))
}

processResources {
inputs.property "version", project.version
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 21
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = 21
}
kotlinOptions {
jvmTarget = 21
}
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}" }
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.15.10
fabric_kotlin_version=1.11.0+kotlin.2.0.0

# Mod Properties
mod_version=2.0.0
mod_version=2.1.4
build_state=beta
maven_group=xyz.koiro.watersource
archives_base_name=watersource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.koiro.watersource.render.blockentity

import com.mojang.blaze3d.systems.RenderSystem
import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper
import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.VertexConsumerProvider
Expand Down Expand Up @@ -62,7 +63,7 @@ class FilterBERenderer : BlockEntityRenderer<FilterBlockEntity> {

matrices.push()
RenderSystem.enableBlend()
val consumer = vertexConsumers.getBuffer(RenderLayer.getGlintTranslucent())
val consumer = vertexConsumers.getBuffer(RenderLayer.getCutout())
val u0 = fluidSprite.minU
val v0 = fluidSprite.minV
val u1 = fluidSprite.maxU
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/xyz/koiro/watersource/mixin/ExampleMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ private void onJump(final CallbackInfo info){
}
}

@Inject(at = @At(value = "INVOKE"), method = "readCustomDataFromNbt")
private void onReadCustomNbt(final NbtCompound nbt, final CallbackInfo info){
@Inject(at = @At(value = "RETURN"), method = "readCustomDataFromNbt")
private void readCustomDataFromNbt(final NbtCompound nbt, final CallbackInfo info){
var player = (net.minecraft.entity.player.PlayerEntity) (Object) this;
if (player instanceof ServerPlayerEntity serverPlayer) {
ActionResult result = ModServerEvents.INSTANCE.getPLAYER_READ_CUSTOM_NBT().invoker().interact(serverPlayer, nbt);
}
}

@Inject(at = @At(value = "INVOKE"), method = "writeCustomDataToNbt")
private void onWriteCustomNbt(final NbtCompound nbt, final CallbackInfo info){
@Inject(at = @At(value = "RETURN"), method = "writeCustomDataToNbt")
private void writeCustomDataToNbt(final NbtCompound nbt, final CallbackInfo info){
var player = (net.minecraft.entity.player.PlayerEntity) (Object) this;
if (player instanceof ServerPlayerEntity serverPlayer) {
ActionResult result = ModServerEvents.INSTANCE.getPLAYER_WRITE_CUSTOM_NBT().invoker().interact(serverPlayer, nbt);
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.text.Text
import xyz.koiro.watersource.api.simpleStack
import xyz.koiro.watersource.api.storage.FluidStorageData
import xyz.koiro.watersource.api.storage.insertFluid
import xyz.koiro.watersource.world.datacomponent.ModDataComponentTypes
import xyz.koiro.watersource.world.enchantment.ModEnchantments
import xyz.koiro.watersource.world.fluid.ModFluids
import xyz.koiro.watersource.world.item.ModItems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class FluidStorageData(
return ret
}

fun copy(): FluidStorageData{
return FluidStorageData(fluid, amount, capacity)
}

fun isBlank(): Boolean {
return amount == 0L || fluid == Fluids.EMPTY
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ fun ItemStack.extractFluid(amount: Long): Long? {
fun ItemStack.getOrCreateFluidStorageData(): FluidStorageData? {
val item = this.item
if (item is FluidContainerItem) {
val data = this.get(ModDataComponentTypes.FLUID_STORAGE)
return if (data != null) {
data
} else {
// Init
val ret = FluidStorageData(Fluids.EMPTY, 0, item.capacity)
this.set(ModDataComponentTypes.FLUID_STORAGE, ret)
ret
}
val data = this.getOrDefault(ModDataComponentTypes.FLUID_STORAGE, FluidStorageData(Fluids.EMPTY, 0, item.capacity))
return data
}
return null
}
Expand All @@ -52,9 +45,12 @@ fun ItemStack.getOrCreateFluidStorageData(): FluidStorageData? {
* Modify fluid storage and apply for nbt if item is `FluidContainer`
* */
fun ItemStack.modifyFluidStorage(action: (ItemStack, FluidStorageData) -> Unit) {
this.getOrCreateFluidStorageData()?.let {
action(this, it)
this.set(ModDataComponentTypes.FLUID_STORAGE, it)
this.getOrCreateFluidStorageData()?.let { data ->
this.apply(ModDataComponentTypes.FLUID_STORAGE, data) {
val applied = it.copy()
action(this, applied)
applied
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtOps
import net.minecraft.registry.RegistryWrapper.WrapperLookup
import java.util.Optional
import java.util.Stack
import kotlin.jvm.optionals.getOrNull

class ItemStorageData(var stack: ItemStack = ItemStack.EMPTY) {
Expand All @@ -29,7 +30,8 @@ class ItemStorageData(var stack: ItemStack = ItemStack.EMPTY) {
stack = ItemStack.EMPTY
}

fun writeNbt(lookup: WrapperLookup, nbtCompound: NbtCompound) {
CODEC.encode(this, lookup.getOps(NbtOps.INSTANCE), nbtCompound).getOrThrow()
fun writeNbt(lookup: WrapperLookup): NbtCompound {
val a = CODEC.encode(this, lookup.getOps(NbtOps.INSTANCE), NbtCompound()).getOrThrow()
return a as NbtCompound
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class StrainerFilteringFluidRecipeJsonBuilder(
return Items.APPLE
}


override fun offerTo(exporter: RecipeExporter, recipeId: Identifier) {
exporter.accept(recipeId, StrainerFilteringFluidRecipe(inFluid, outFluid, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/")))
exporter.accept(id, StrainerFilteringFluidRecipe(inFluid, outFluid, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class StrainerFilteringItemRecipeJsonBuilder(
}

override fun offerTo(exporter: RecipeExporter, recipeId: Identifier) {
exporter.accept(recipeId, StrainerFilteringItemRecipe(input, output, cost, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/")))
exporter.accept(id, StrainerFilteringItemRecipe(input, output, cost, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ class FilterBlockEntity(pos: BlockPos, state: BlockState, var capacity: Long, va
super.writeNbt(nbt, registryLookup)
if (nbt == null || registryLookup == null) return
nbt.putBoolean("isUp", isUp)
val strainerNbt = NbtCompound()
strainerStorage.writeNbt(registryLookup, strainerNbt)
val strainerNbt = strainerStorage.writeNbt(registryLookup)
nbt.put("strainer", strainerNbt)
nbt.putBoolean("isWorking", isWorking)
nbt.putInt("ticks", filterTicks)
Expand Down
Loading

0 comments on commit 423f2fa

Please sign in to comment.