Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish 1.20.2 port and replace Patchouli with Lavender #52

Merged
merged 5 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ repositories {
maven {
url "https://maven.ladysnake.org/releases"
}
/* Patchouli */
maven { url 'https://maven.blamejared.com' }
/* Lavender */
maven { url 'https://maven.wispforest.io/releases/' }

}

Expand Down Expand Up @@ -60,7 +60,7 @@ dependencies {
modImplementation include("maven.modrinth:midnightlib:${project.midnightlib_version}")

// Patchouli
modImplementation "vazkii.patchouli:Patchouli:${project.patchouli_version}"
modImplementation include("io.wispforest:lavender:${project.lavender_version}")


// Uncomment the following line to enable Bovines and Buttercups for testing the integration.
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
loader_version=0.15.3

# Mod Properties
mod_version = 1.1.4
Expand All @@ -23,8 +23,8 @@ rei_version=13.0.666
# EMI
emi_version=1.0.22+1.20.2
# MidnightLib
midnightlib_version=1.4.1-fabric
midnightlib_version=1.5.0-fabric
# Bovines and Buttercups
bovines_version=1.9.0+1.20.1
# Patchouli
patchouli_version=1.20.1-81-FABRIC
# Lavender
lavender_version=0.1.0-pre.19+1.20.2
25 changes: 25 additions & 0 deletions src/main/java/com/seacroak/plushables/PlushablesModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,32 @@
import com.seacroak.plushables.networking.ParticlePacketHandler.ParticlePacket;
import com.seacroak.plushables.networking.SoundPacketHandler.NoPlayerSoundPacket;
import com.seacroak.plushables.networking.SoundPacketHandler.PlayerSoundPacket;
import com.seacroak.plushables.recipe.BuilderRecipe;
import com.seacroak.plushables.registry.MainRegistry;
import com.seacroak.plushables.registry.client.EntityRendererRegistry;
import com.seacroak.plushables.registry.client.ScreenRegistry;
import com.seacroak.plushables.registry.client.TileRegistryClient;
import io.wispforest.lavender.client.LavenderBookScreen;
import io.wispforest.lavender.md.features.RecipeFeature;
import io.wispforest.owo.ui.component.ItemComponent;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.StackLayout;
import io.wispforest.owo.ui.core.ParentComponent;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import java.util.Map;

public final class PlushablesModClient implements ClientModInitializer {
public static boolean onServer = false;

Expand Down Expand Up @@ -121,5 +133,18 @@ public void onInitializeClient() {

});
}));

LavenderBookScreen.registerRecipePreviewBuilder(new Identifier("plushables:codex"), BuilderRecipe.Type.INSTANCE, (componentSource, recipeEntry) -> {
var preview = componentSource.template(new Identifier("plushables:codex"), ParentComponent.class, "builder-recipe", Map.of());

preview.childById(StackLayout.class, "title-anchor").child(componentSource.builtinTemplate(FlowLayout.class, "page-title", Map.of("title", Text.translatable("item.plushables.codex.builder_recipe").getString())));

preview.childById(RecipeFeature.IngredientComponent.class, "top-input").ingredient(recipeEntry.value().getRecipeItems().get(0));
preview.childById(RecipeFeature.IngredientComponent.class, "bottom-input").ingredient(recipeEntry.value().getRecipeItems().get(1));
preview.childById(RecipeFeature.IngredientComponent.class, "heart-input").ingredient(recipeEntry.value().getRecipeItems().get(2));
preview.childById(ItemComponent.class, "result").stack(recipeEntry.value().getResult(MinecraftClient.getInstance().world.getRegistryManager()));

return preview;
});
}
}
10 changes: 8 additions & 2 deletions src/main/java/com/seacroak/plushables/block/BasketBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void onBlockBreakStart(BlockState state, World world, BlockPos pos, Playe
float randomPitch = 0.85f + random.nextFloat() / 4;
BlockEntity be = world.getBlockEntity(pos);
if (!(be instanceof BasketBlockEntity)) return;
ItemStack[] poppedStack = ((BasketBlockEntity) be).popAll(player);
ItemStack[] poppedStack = ((BasketBlockEntity) be).popAll();
/* Checks whether the lowest index in the basket's stack isn't empty */
if (poppedStack[0].isOf(Items.AIR)) return;
if (world instanceof ServerWorld serverWorld) {
Expand All @@ -135,8 +135,14 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
return;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BasketBlockEntity) {
if (blockEntity instanceof BasketBlockEntity basket) {
world.updateComparators(pos, this);

ItemStack[] poppedStack = basket.popAll();
for (var plush : poppedStack) {
if (plush.isEmpty()) continue;
ItemScatterer.spawn(world, pos.getX() + 0.5 + (0.5 * ((2 * random.nextFloat()) - 1)), pos.getY() + 0.5 + random.nextFloat(), pos.getZ() + 0.5 + (0.5 * ((2 * random.nextFloat()) - 1)), plush);
}
}
super.onStateReplaced(state, world, pos, newState, moved);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/seacroak/plushables/block/CodexBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.seacroak.plushables.block;

import com.seacroak.plushables.registry.MainRegistry;
import com.seacroak.plushables.util.VoxelShapeUtils;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
Expand Down Expand Up @@ -34,7 +35,7 @@ public CodexBlock() {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world instanceof ServerWorld serverWorld) {
ItemScatterer.spawn(world, pos, DefaultedList.ofSize(1, new ItemStack(this)));
ItemScatterer.spawn(world, pos, DefaultedList.ofSize(1, new ItemStack(MainRegistry.CODEX_ITEM)));
world.updateComparators(pos, this);
world.removeBlock(pos, false);
return ActionResult.CONSUME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private void renderProgressArrow(DrawContext context, int x, int y) {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
context.drawText( textRenderer, Text.translatable("block.plushables.builder_block"), x + 4,y - 8, 0xffffff, true );

renderBackground(context,mouseX,mouseY,delta);
super.render(context, mouseX, mouseY, delta);
drawMouseoverTooltip(context, mouseX, mouseY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean popPlush(PlayerEntity player) {
return true;
}

public ItemStack[] popAll(PlayerEntity player) {
public ItemStack[] popAll() {
ItemStack[] poppedItems = Arrays.copyOf(plushStack, 8);
/* Reset plush stack to empty values */
Arrays.fill(plushStack, ItemStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static void craftItem(BuilderTileEntity entity) {
entity.removeStack(0, 1);
entity.removeStack(1, 1);
entity.removeStack(2, 1);
entity.setStack(3, new ItemStack(match.get().getResult(entity.world.getRegistryManager()).getItem(),
entity.setStack(3, new ItemStack(match.get().value().getResult(entity.world.getRegistryManager()).getItem(),
entity.getStack(3).getCount() + 1));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void register(EmiRegistry registry) {
registry.addWorkstation(BUILDER_CATEGORY, BUILDER_BLOCK);

for (RecipeEntry<BuilderRecipe> recipe : registry.getRecipeManager().listAllOfType(BuilderRecipe.Type.INSTANCE)) {
registry.addRecipe(new PlushablesEMIRecipe(recipe.value()));
registry.addRecipe(new PlushablesEMIRecipe(recipe));
}

registry.addRecipeHandler(ScreenRegistry.BUILDER_SCREEN_HANDLER, new BuilderEMIRecipeHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

Expand All @@ -25,12 +26,12 @@ public class PlushablesEMIRecipe implements EmiRecipe {
private final List<EmiIngredient> inputs = new ArrayList<>();
private final List<EmiStack> outputs = new ArrayList<>();

public PlushablesEMIRecipe(BuilderRecipe recipe) {
this.id = recipe.getId();
this.inputs.add(EmiIngredient.of(recipe.getRecipeItems().get(0)));
this.inputs.add(EmiIngredient.of(recipe.getRecipeItems().get(1)));
this.inputs.add(EmiIngredient.of(recipe.getRecipeItems().get(2)));
this.outputs.add(EmiStack.of(recipe.getResult(null)));
public PlushablesEMIRecipe(RecipeEntry<BuilderRecipe> recipeEntry) {
this.id = recipeEntry.id();
this.inputs.add(EmiIngredient.of(recipeEntry.value().getRecipeItems().get(0)));
this.inputs.add(EmiIngredient.of(recipeEntry.value().getRecipeItems().get(1)));
this.inputs.add(EmiIngredient.of(recipeEntry.value().getRecipeItems().get(2)));
this.outputs.add(EmiStack.of(recipeEntry.value().getResult(null)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.recipe.RecipeEntry;

import java.util.List;

public record BuilderDisplay(List<EntryIngredient> inputs, List<EntryIngredient> output) implements Display {

public BuilderDisplay(BuilderRecipe recipe) {
public BuilderDisplay(RecipeEntry<BuilderRecipe> recipe) {
this(
recipe.getRecipeItems().stream().map(EntryIngredients::ofIngredient).toList(),
List.of(EntryIngredients.of(recipe.getResult(null)))
recipe.value().getRecipeItems().stream().map(EntryIngredients::ofIngredient).toList(),
List.of(EntryIngredients.of(recipe.value().getResult(null)))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PlushablesREIClientPlugin implements REIClientPlugin {

@Override
public void registerDisplays(DisplayRegistry registry) {
registry.registerFiller(BuilderRecipe.class, BuilderDisplay::new);
registry.registerRecipeFiller(BuilderRecipe.class, BuilderRecipe.Type.INSTANCE, BuilderDisplay::new);
}

@Override
Expand Down
68 changes: 32 additions & 36 deletions src/main/java/com/seacroak/plushables/item/CodexItem.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
package com.seacroak.plushables.item;

import com.seacroak.plushables.block.BasePlushable;
import com.seacroak.plushables.registry.MainRegistry;
import io.wispforest.lavender.book.LavenderBookItem;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import vazkii.patchouli.api.PatchouliAPI;
import net.minecraft.world.event.GameEvent;

public class CodexItem extends BlockItem {
public class CodexItem extends LavenderBookItem {

public CodexItem(Block block, FabricItemSettings settings) {
super(block, settings);
public CodexItem(FabricItemSettings settings) {
super(settings, new Identifier("plushables:codex"));
}

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
PlayerEntity player = context.getPlayer();
if (!player.isSneaking()) {
if (player instanceof ServerPlayerEntity sp) {
PatchouliAPI.get().openBookGUI(sp, new Identifier("plushables:codex"));
return ActionResult.SUCCESS;
}
} else {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
/* This line allows for patchouli plushable entries to be viewed on shift right click */
if (world.getBlockState(pos).getBlock() instanceof BasePlushable) return ActionResult.PASS;
return super.useOnBlock(context);
}
return ActionResult.PASS;
}
if (!context.getPlayer().isSneaking()) return ActionResult.PASS;

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
var world = context.getWorld();
var placePos = context.getBlockPos().offset(context.getSide());

var newState = MainRegistry.CODEX_BLOCK.getDefaultState();
if (!newState.canPlaceAt(world, placePos)) return ActionResult.PASS;

if (player instanceof ServerPlayerEntity sp) {
PatchouliAPI.get().openBookGUI(sp, new Identifier("plushables:codex"));
world.setBlockState(placePos, newState, Block.REDRAW_ON_MAIN_THREAD | Block.NO_REDRAW | Block.NOTIFY_NEIGHBORS);
world.emitGameEvent(context.getPlayer(), GameEvent.BLOCK_PLACE, context.getBlockPos());

world.playSound(
context.getPlayer(),
placePos,
newState.getSoundGroup().getPlaceSound(),
SoundCategory.BLOCKS,
(newState.getSoundGroup().getVolume() + 1f) / 2f,
newState.getSoundGroup().getPitch() * .8f
);

if (context.getPlayer() instanceof ServerPlayerEntity player) {
Criteria.PLACED_BLOCK.trigger(player, placePos, context.getStack());
}

if (world.isClient()) {
return TypedActionResult.success(stack);
} else {
return TypedActionResult.consume(stack);
if (context.getPlayer() == null || !context.getPlayer().getAbilities().creativeMode) {
context.getStack().decrement(1);
}

return ActionResult.success(world.isClient);
}
}
39 changes: 13 additions & 26 deletions src/main/java/com/seacroak/plushables/recipe/BuilderRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -13,8 +14,15 @@
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;

import java.util.function.Function;

public class BuilderRecipe implements Recipe<SimpleInventory> {

public static final Codec<BuilderRecipe> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RecipeCodecs.CRAFTING_RESULT.fieldOf("output").forGetter(recipe -> recipe.output),
Ingredient.DISALLOW_EMPTY_CODEC.listOf().xmap(ingredients -> DefaultedList.copyOf(Ingredient.EMPTY, ingredients.toArray(Ingredient[]::new)), Function.identity()).fieldOf("ingredients").forGetter(recipe -> recipe.recipeItems)
).apply(instance, BuilderRecipe::new));

private final ItemStack output;
private final DefaultedList<Ingredient> recipeItems;

Expand Down Expand Up @@ -64,8 +72,7 @@ public RecipeType<?> getType() {
}

public static class Type implements RecipeType<BuilderRecipe> {
private Type() {
}
private Type() {}

public static final Type INSTANCE = new Type();
public static final String ID = "builder";
Expand All @@ -77,43 +84,23 @@ public static class Serializer implements RecipeSerializer<BuilderRecipe> {
// this is the name given in the json file

@Override
public BuilderRecipe read(Identifier id, JsonObject json) {
ItemStack output = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, "output"));

JsonArray ingredients = JsonHelper.getArray(json, "ingredients");
DefaultedList<Ingredient> inputs = DefaultedList.ofSize(3, Ingredient.EMPTY);

for (int i = 0; i < inputs.size(); i++) {
inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
}

return new BuilderRecipe(id, output, inputs);
public Codec<BuilderRecipe> codec() {
return BuilderRecipe.CODEC;
}

@Override
public BuilderRecipe read(Identifier id, PacketByteBuf buf) {
public BuilderRecipe read(PacketByteBuf buf) {
DefaultedList<Ingredient> inputs = DefaultedList.ofSize(buf.readInt(), Ingredient.EMPTY);

for (int i = 0; i < inputs.size(); i++) {
inputs.set(i, Ingredient.fromPacket(buf));
}
ItemStack output = buf.readItemStack();
return new BuilderRecipe(id, output, inputs);
}

@Override
public Codec<BuilderRecipe> codec() {
return null;
}

@Override
public BuilderRecipe read(PacketByteBuf buf) {
return null;
return new BuilderRecipe(output, inputs);
}

@Override
public void write(PacketByteBuf buf, BuilderRecipe recipe) {

buf.writeInt(recipe.getRecipeItems().size());
for (Ingredient ing : recipe.getRecipeItems()) {
ing.write(buf);
Expand Down
Loading
Loading