-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from UselessBullets/recipeFixes
Recipe fixes
- Loading branch information
Showing
4 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package turniplabs.halplibe.mixin.mixins; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.core.data.registry.recipe.adapter.ItemStackJsonAdapter; | ||
import net.minecraft.core.item.Item; | ||
import net.minecraft.core.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
@Mixin(value = ItemStackJsonAdapter.class, remap = false) | ||
public class ItemStackJsonAdapterMixin { | ||
@Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/core/item/ItemStack;", | ||
at = @At("HEAD"), cancellable = true) | ||
protected void deserializeKey(JsonElement json, Type typeOfT, JsonDeserializationContext context, CallbackInfoReturnable<ItemStack> cir){ | ||
JsonObject obj = json.getAsJsonObject(); | ||
if (obj.has("key")){ | ||
ItemStack stack = obj.has("amount") ? new ItemStack(getItemFromKey(obj.get("key").getAsString()), obj.get("amount").getAsInt(), obj.get("meta").getAsInt()) : new ItemStack(getItemFromKey(obj.get("key").getAsString()), 1, obj.get("meta").getAsInt()); | ||
cir.setReturnValue(stack); | ||
} | ||
} | ||
@Unique | ||
private Item getItemFromKey(String key){ | ||
for(Item item : Item.itemsList) { | ||
if (item != null) { | ||
if (item.getKey().equalsIgnoreCase(key)) { | ||
return item; | ||
} | ||
} | ||
} | ||
throw new NullPointerException("Could not find an item that corresponds to key '" + key + "'"); | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
src/main/java/turniplabs/halplibe/mixin/mixins/MinecraftServerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package turniplabs.halplibe.mixin.mixins; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.server.MinecraftServer; | ||
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; | ||
import turniplabs.halplibe.util.RecipeEntrypoint; | ||
|
||
@Mixin(value = MinecraftServer.class, remap = false) | ||
public class MinecraftServerMixin { | ||
@Inject(method = "startServer", at = @At(value = "INVOKE",target = "Lnet/minecraft/core/data/DataLoader;loadRecipes(Ljava/lang/String;)V", ordinal = 3, shift = At.Shift.AFTER)) | ||
public void recipeEntrypoint(CallbackInfoReturnable<Boolean> cir){ | ||
FabricLoader.getInstance().getEntrypoints("recipesReady", RecipeEntrypoint.class).forEach(RecipeEntrypoint::onRecipesReady); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters