Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Oct 28, 2024
1 parent 248cd85 commit d1736b2
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.nova.nmt.gui.EnderBrewingStandMenu;
import net.nova.nmt.init.NMTBlockEntities;
import net.nova.nmt.init.NMTItems;

Expand Down Expand Up @@ -151,6 +152,6 @@ public boolean canTakeItemThroughFace(int index, ItemStack stack, Direction dire

@Override
protected AbstractContainerMenu createMenu(int id, Inventory player) {
return new BrewingStandMenu(id, player, this, this.dataAccess);
return new EnderBrewingStandMenu(id, player, this, this.dataAccess);
}
}
196 changes: 196 additions & 0 deletions src/main/java/net/nova/nmt/gui/EnderBrewingStandMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package net.nova.nmt.gui;

import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.PotionContents;

import java.util.Optional;

public class EnderBrewingStandMenu extends AbstractContainerMenu {
private static final int BOTTLE_SLOT_START = 0;
private static final int BOTTLE_SLOT_END = 2;
private static final int INGREDIENT_SLOT = 3;
private static final int FUEL_SLOT = 4;
private static final int SLOT_COUNT = 5;
private static final int DATA_COUNT = 2;
private static final int INV_SLOT_START = 5;
private static final int INV_SLOT_END = 32;
private static final int USE_ROW_SLOT_START = 32;
private static final int USE_ROW_SLOT_END = 41;
private final Container brewingStand;
private final ContainerData brewingStandData;
private final Slot ingredientSlot;

public EnderBrewingStandMenu(int containerId, Inventory playerInventory) {
this(containerId, playerInventory, new SimpleContainer(5), new SimpleContainerData(2));
}

public EnderBrewingStandMenu(int containerId, Inventory playerInventory, Container brewingStandContainer, ContainerData brewingStandData) {
super(MenuType.BREWING_STAND, containerId);
checkContainerSize(brewingStandContainer, 5);
checkContainerDataCount(brewingStandData, 2);
this.brewingStand = brewingStandContainer;
this.brewingStandData = brewingStandData;
PotionBrewing potionbrewing = playerInventory.player.level().potionBrewing();
this.addSlot(new EnderBrewingStandMenu.PotionSlot(potionbrewing, brewingStandContainer, 0, 56, 51));
this.addSlot(new EnderBrewingStandMenu.PotionSlot(potionbrewing, brewingStandContainer, 1, 79, 58));
this.addSlot(new EnderBrewingStandMenu.PotionSlot(potionbrewing, brewingStandContainer, 2, 102, 51));
this.ingredientSlot = this.addSlot(new EnderBrewingStandMenu.IngredientsSlot(potionbrewing, brewingStandContainer, 3, 79, 17));
this.addSlot(new EnderBrewingStandMenu.FuelSlot(brewingStandContainer, 4, 17, 17));
this.addDataSlots(brewingStandData);

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}

for (int k = 0; k < 9; k++) {
this.addSlot(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}

@Override
public boolean stillValid(Player player) {
return this.brewingStand.stillValid(player);
}

@Override
public ItemStack quickMoveStack(Player player, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
if ((index < 0 || index > 2) && index != 3 && index != 4) {
if (EnderBrewingStandMenu.FuelSlot.mayPlaceItem(itemstack)) {
if (this.moveItemStackTo(itemstack1, 4, 5, false)
|| this.ingredientSlot.mayPlace(itemstack1) && !this.moveItemStackTo(itemstack1, 3, 4, false)) {
return ItemStack.EMPTY;
}
} else if (this.ingredientSlot.mayPlace(itemstack1)) {
if (!this.moveItemStackTo(itemstack1, 3, 4, false)) {
return ItemStack.EMPTY;
}
} else if (EnderBrewingStandMenu.PotionSlot.mayPlaceItem(player.level().potionBrewing(), itemstack)) {
if (!this.moveItemStackTo(itemstack1, 0, 3, false)) {
return ItemStack.EMPTY;
}
} else if (index >= 5 && index < 32) {
if (!this.moveItemStackTo(itemstack1, 32, 41, false)) {
return ItemStack.EMPTY;
}
} else if (index >= 32 && index < 41) {
if (!this.moveItemStackTo(itemstack1, 5, 32, false)) {
return ItemStack.EMPTY;
}
} else if (!this.moveItemStackTo(itemstack1, 5, 41, false)) {
return ItemStack.EMPTY;
}
} else {
if (!this.moveItemStackTo(itemstack1, 5, 41, true)) {
return ItemStack.EMPTY;
}

slot.onQuickCraft(itemstack1, itemstack);
}

if (itemstack1.isEmpty()) {
slot.setByPlayer(ItemStack.EMPTY);
} else {
slot.setChanged();
}

if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}

slot.onTake(player, itemstack);
}

return itemstack;
}

static class FuelSlot extends Slot {
public FuelSlot(Container container, int slot, int x, int y) {
super(container, slot, x, y);
}

@Override
public boolean mayPlace(ItemStack stack) {
return mayPlaceItem(stack);
}

public static boolean mayPlaceItem(ItemStack itemStack) {
return itemStack.is(Items.BLAZE_POWDER);
}
}

static class IngredientsSlot extends Slot {
private final PotionBrewing potionBrewing;

public IngredientsSlot(PotionBrewing potionBrewing, Container container, int slot, int x, int y) {
super(container, slot, x, y);
this.potionBrewing = potionBrewing;
}

@Override
public boolean mayPlace(ItemStack stack) {
return this.potionBrewing.isIngredient(stack);
}
}

static class PotionSlot extends Slot {
private final PotionBrewing potionBrewing;

public PotionSlot(Container container, int slot, int x, int y) {
this(PotionBrewing.EMPTY, container, slot, x, y);
}

public PotionSlot(PotionBrewing potionBrewing, Container p_39123_, int p_39124_, int p_39125_, int p_39126_) {
super(p_39123_, p_39124_, p_39125_, p_39126_);
this.potionBrewing = potionBrewing;
}

@Override
public boolean mayPlace(ItemStack stack) {
return mayPlaceItem(this.potionBrewing, stack);
}

@Override
public int getMaxStackSize() {
return 1;
}

@Override
public void onTake(Player player, ItemStack stack) {
Optional<Holder<Potion>> optional = stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion();
if (optional.isPresent() && player instanceof ServerPlayer serverplayer) {
net.neoforged.neoforge.event.EventHooks.onPlayerBrewedPotion(player, stack);
CriteriaTriggers.BREWED_POTION.trigger(serverplayer, optional.get());
}

super.onTake(player, stack);
}

@Deprecated
public static boolean mayPlaceItem(ItemStack stack) {
return stack.is(Items.POTION) || stack.is(Items.SPLASH_POTION) || stack.is(Items.LINGERING_POTION) || stack.is(Items.GLASS_BOTTLE);
}

public static boolean mayPlaceItem(PotionBrewing potionBrewing, ItemStack p_39134_) {
return potionBrewing.isInput(p_39134_) || p_39134_.is(Items.GLASS_BOTTLE);
}
}
}

0 comments on commit d1736b2

Please sign in to comment.