Skip to content

Commit

Permalink
Fixed 1.16 version screens and server
Browse files Browse the repository at this point in the history
  • Loading branch information
stuin committed Jun 25, 2021
1 parent 7b35cac commit 0bd27bd
Show file tree
Hide file tree
Showing 18 changed files with 270 additions and 288 deletions.
1 change: 0 additions & 1 deletion src/main/java/modfest/lacrimis/Lacrimis.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void onInitialize() {
ModEntities.register();
ModItems.register();
ModCrafting.register();
ModNetworking.register();
ModSounds.register();
ModParticles.register();
ModStatusEffects.register();
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/modfest/lacrimis/block/CombinerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ public BlockEntity createBlockEntity(BlockView world) {
return new CombinerEntity();
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ActionResult parentResult = super.onUse(state, world, pos, player, hand, hit);
if(parentResult == ActionResult.PASS && player.getStackInHand(hand).getItem() != ModItems.diviningRod) {
if(world.isClient) {
return ActionResult.SUCCESS;
} else {
ContainerProviderRegistry.INSTANCE.openContainer(ModCrafting.COMBINER_SCREEN_ID, player, buf -> buf.writeBlockPos(pos));

return ActionResult.CONSUME;
if (world.isClient) {
return ActionResult.SUCCESS;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof CombinerEntity) {
player.openHandledScreen((CombinerEntity)blockEntity);
}

return ActionResult.CONSUME;
}
return parentResult;
}

@Override
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/modfest/lacrimis/block/InfusionTableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,25 @@ public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ActionResult parentResult = super.onUse(state, world, pos, player, hand, hit);
if(parentResult == ActionResult.PASS && player.getStackInHand(hand).getItem() != ModItems.diviningRod) {
if(world.isClient) {
return ActionResult.SUCCESS;
} else {
ContainerProviderRegistry.INSTANCE.openContainer(ModCrafting.INFUSION_SCREEN_ID, player, buf -> buf.writeBlockPos(pos));

return ActionResult.CONSUME;
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
return ActionResult.SUCCESS;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof InfusionTableEntity) {
player.openHandledScreen((InfusionTableEntity)blockEntity);
}

return ActionResult.CONSUME;
}
return parentResult;
}

@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
if(state.get(POWERED) != world.isReceivingRedstonePower(pos)) {
BlockEntity entity = world.getBlockEntity(pos);
if(!state.get(POWERED) && entity instanceof InfusionTableEntity)
((InfusionTableEntity) entity).startCrafting = true;
((InfusionTableEntity) entity).inventory.properties.setSignal(true);
world.setBlockState(pos, state.with(POWERED, world.isReceivingRedstonePower(pos)));
}
}
Expand Down
35 changes: 33 additions & 2 deletions src/main/java/modfest/lacrimis/block/entity/CombinerEntity.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
package modfest.lacrimis.block.entity;

import modfest.lacrimis.crafting.CombinerScreenHandler;
import modfest.lacrimis.init.ModEntities;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;

public class CombinerEntity extends SoulTankEntity {
public class CombinerEntity extends SoulTankEntity implements ExtendedScreenHandlerFactory {
public static final int SIZE = 2;
public EntityType<?> type;

public CombinerEntity() {
super(ModEntities.combiner, 0, 2);
super(ModEntities.combiner, 0, SIZE);
type = null;
}

@Override
public Text getDisplayName() {
return new TranslatableText("lacrimis.gui.combiner");
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
return new CombinerScreenHandler(syncId, inv, inventory, type, pos);
}

@Override
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
String s = "null";
if(type != null)
s = Registry.ENTITY_TYPE.getId(type).toString();
buf.writeBlockPos(pos);
buf.writeString(s);
}

@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,52 @@
import java.util.stream.IntStream;

import modfest.lacrimis.crafting.InfusionRecipe;
import modfest.lacrimis.crafting.InfusionScreenHandler;
import modfest.lacrimis.init.ModCrafting;
import modfest.lacrimis.init.ModEntities;
import modfest.lacrimis.init.ModParticles;
import modfest.lacrimis.util.DuctUtil;
import modfest.lacrimis.util.SoulTank;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.Nullable;

public class InfusionTableEntity extends SoulTankEntity implements Tickable {
public class InfusionTableEntity extends SoulTankEntity implements Tickable, NamedScreenHandlerFactory {
public static final int CAPACITY = 1000;
public static final int SIZE = 10;
public static final int OUTPUT_STACK = 9;
public static final int[] INPUT_STACKS = IntStream.rangeClosed(0, 8).toArray();
private final Random random = new Random();

public ItemStack holding = ItemStack.EMPTY;
public boolean startCrafting = false;

public InfusionTableEntity() {
super(ModEntities.infusionTable, 1000, 10);
getTank().setLimit(0);
}

@Override
public Text getDisplayName() {
return new TranslatableText("lacrimis.gui.infusion");
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
return new InfusionScreenHandler(syncId, inv, inventory);
}

@Override
public void tick() {
if(world == null)
Expand Down Expand Up @@ -68,7 +87,7 @@ else if (holding.getItem() == output.getItem())
}

//Check for new recipe
if(holding.isEmpty() && (startCrafting || !inventory.getStack(OUTPUT_STACK).isEmpty())) {
if(holding.isEmpty() && (inventory.properties.hasSignal() || !inventory.getStack(OUTPUT_STACK).isEmpty())) {
InfusionRecipe recipe = this.world.getRecipeManager().getFirstMatch(ModCrafting.INFUSION_RECIPE, inventory, this.world).orElse(null);
if(recipe == null)
recipe = this.world.getRecipeManager().getFirstMatch(ModCrafting.CRUCIBLE_RECIPE, inventory, this.world).orElse(null);
Expand All @@ -82,17 +101,17 @@ else if (holding.getItem() == output.getItem())
takeIngredients();
tank.setLimit(recipe.getTears());
holding = recipe.getOutput().copy();
startCrafting = false;
inventory.properties.setSignal(false);
} else if(vanillaRecipe != null && canAcceptOutput(vanillaRecipe.getOutput())) {
takeIngredients();
tank.setLimit(5);
holding = vanillaRecipe.getOutput().copy();
startCrafting = false;
inventory.properties.setSignal(false);
}
}

if(startCrafting)
startCrafting = false;
if(inventory.properties.hasSignal())
inventory.properties.setSignal(false);

//Collect tears
if(tank.getSpace() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SoulTankEntity(BlockEntityType<?> type, int capacity, int inventory) {
super(type);
tank = new SoulTank(capacity);
tank.addListener(this::mark);
this.inventory = new InfusionInventory(this, inventory);
this.inventory = new InfusionInventory(tank, inventory);
}

public float getRelativeLevel() {
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/modfest/lacrimis/client/init/ClientModCrafting.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package modfest.lacrimis.client.init;

import modfest.lacrimis.Lacrimis;
import modfest.lacrimis.client.render.screen.CombinerScreen;
import modfest.lacrimis.client.render.screen.InfusionScreen;
import modfest.lacrimis.compat.patchiouli.PageCrucible;
import modfest.lacrimis.compat.patchiouli.PageInfusion;
import modfest.lacrimis.crafting.CombinerScreen;
import modfest.lacrimis.crafting.CombinerScreenHandler;
import modfest.lacrimis.crafting.InfusionScreen;
import modfest.lacrimis.crafting.InfusionScreenHandler;
import modfest.lacrimis.init.ModCrafting;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.TranslatableText;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.minecraft.util.Identifier;
import vazkii.patchouli.client.book.ClientBookRegistry;

public class ClientModCrafting {
public static void registerClient() {
if(MinecraftClient.getInstance().player != null) {
// Infusion GUI
ScreenProviderRegistry.INSTANCE.<InfusionScreenHandler>registerFactory(ModCrafting.INFUSION_SCREEN_ID,
container -> new InfusionScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText(Lacrimis.MODID + ".gui.infusion")));
ScreenProviderRegistry.INSTANCE.<CombinerScreenHandler>registerFactory(ModCrafting.COMBINER_SCREEN_ID,
container -> new CombinerScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText(Lacrimis.MODID + ".gui.combiner")));
}
ScreenRegistry.register(ModCrafting.INFUSION_SCREEN_HANDLER, InfusionScreen::new);
ScreenRegistry.register(ModCrafting.COMBINER_SCREEN_HANDLER, CombinerScreen::new);

// Patchouli pages
ClientBookRegistry.INSTANCE.pageTypes.put(new Identifier(Lacrimis.MODID, "crucible"), PageCrucible.class);
ClientBookRegistry.INSTANCE.pageTypes.put(new Identifier(Lacrimis.MODID, "infusion"), PageInfusion.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,4 @@ private static void handleCrucibleParticlesPacket(MinecraftClient client, Client
}
});
}

public static void sendCombinerNullPacket(BlockPos pos) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(pos);
ClientPlayNetworking.send(COMBINER_NULL_ID, buf);
}

public static void sendInfusionStartPacket(BlockPos pos) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(pos);
ClientPlayNetworking.send(INFUSION_START_ID, buf);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package modfest.lacrimis.crafting;
package modfest.lacrimis.client.render.screen;

import com.mojang.blaze3d.systems.RenderSystem;
import modfest.lacrimis.Lacrimis;
import modfest.lacrimis.crafting.CombinerScreenHandler;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package modfest.lacrimis.crafting;
package modfest.lacrimis.client.render.screen;

import com.mojang.blaze3d.systems.RenderSystem;

import modfest.lacrimis.Lacrimis;
import modfest.lacrimis.crafting.InfusionScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.screen.EnchantmentScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand All @@ -21,7 +20,6 @@
public class InfusionScreen extends HandledScreen<InfusionScreenHandler> {
private static final Identifier TEXTURE = new Identifier("textures/gui/container/crafting_table.png");
private static final Identifier START_BUTTON_TEXTURE = new Identifier(Lacrimis.MODID, "textures/gui/start_button.png");
private TexturedButtonWidget startButton;
private boolean isNarrow;

public InfusionScreen(InfusionScreenHandler handler, PlayerInventory inventory, Text title) {
Expand All @@ -32,8 +30,8 @@ public InfusionScreen(InfusionScreenHandler handler, PlayerInventory inventory,
protected void init() {
super.init();
isNarrow = width < 379;
startButton = new TexturedButtonWidget(x + backgroundWidth - 54, y + titleY + 3, 20, 18, 0, 0, 19, START_BUTTON_TEXTURE, (buttonWidget) -> {
handler.startCrafting();
TexturedButtonWidget startButton = new TexturedButtonWidget(x + backgroundWidth - 54, y + titleY + 3, 20, 18, 0, 0, 19, START_BUTTON_TEXTURE, (buttonWidget) -> {
this.client.interactionManager.clickButton(this.handler.syncId, 0);
});
addButton(startButton);
titleX = 24;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package modfest.lacrimis.compat.patchiouli;

import com.google.gson.annotations.SerializedName;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import com.mojang.blaze3d.systems.RenderSystem;

Expand All @@ -15,13 +17,16 @@
import modfest.lacrimis.init.ModCrafting;

public class PageInfusion extends PageDoubleRecipeRegistry<InfusionRecipe> {
@SerializedName("crafting_texture")
public static final Identifier TEXTURE = new Identifier("lacrimis", "textures/gui/crafting.png");

public PageInfusion() {
super(ModCrafting.INFUSION_RECIPE);
}

@Override
protected void drawRecipe(MatrixStack ms, InfusionRecipe recipe, int recipeX, int recipeY, int mouseX, int mouseY, boolean second) {
this.mc.getTextureManager().bindTexture(ModCrafting.craftingTexture);
this.mc.getTextureManager().bindTexture(TEXTURE);
RenderSystem.enableBlend();
DrawableHelper.drawTexture(ms, recipeX - 2, recipeY - 2, 0.0F, 0.0F, 100, 62, 128, 128);
boolean shaped = recipe instanceof ShapedInfusionRecipe;
Expand Down
Loading

0 comments on commit 0bd27bd

Please sign in to comment.