Skip to content

Commit

Permalink
feat: Move ItemModes from an enum system to classes (#1071) - thanks @…
Browse files Browse the repository at this point in the history
…GaeaKat!

* feat: move ItemMode from enum into classes

* feat: move gui into ItemMode

* fix: remove old enum system from calling books

* chore: minor Cleanup

* fix: removed extra debug information
  • Loading branch information
GaeaKat committed Mar 7, 2024
1 parent d3a5620 commit c892040
Show file tree
Hide file tree
Showing 15 changed files with 718 additions and 497 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.klikli_dev.occultism.api.common.data.WorkAreaSize;
import com.klikli_dev.occultism.client.gui.spirit.BookOfCallingGui;
import com.klikli_dev.occultism.client.gui.spirit.BookOfCallingManagedMachineGui;
import com.klikli_dev.occultism.common.item.spirit.BookOfCallingItem;
import com.klikli_dev.occultism.common.item.spirit.calling.ItemMode;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Direction;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -42,7 +42,11 @@ public static void openBookOfCallingManagedMachineGui(Direction insertFacing, Di
}

@OnlyIn(Dist.CLIENT)
public static void openBookOfCallingGui(BookOfCallingItem.IItemModeSubset<?> itemMode, WorkAreaSize workAreaSize) {
public static void openBookOfCallingGui(ItemMode itemMode, WorkAreaSize workAreaSize) {
itemMode.openGUI(workAreaSize);
}

public static void openBookOfCallingGui_internal(ItemMode itemMode, WorkAreaSize workAreaSize) {
Minecraft.getInstance().setScreen(new BookOfCallingGui(itemMode, workAreaSize));
}
//endregion Static Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@
import com.klikli_dev.occultism.api.common.data.WorkAreaSize;
import com.klikli_dev.occultism.client.gui.controls.LabelWidget;
import com.klikli_dev.occultism.common.item.spirit.BookOfCallingItem;
import com.klikli_dev.occultism.common.item.spirit.calling.ItemMode;
import com.klikli_dev.occultism.network.MessageSetItemMode;
import com.klikli_dev.occultism.network.MessageSetWorkAreaSize;
import com.klikli_dev.occultism.network.OccultismPackets;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.gui.widget.ExtendedButton;

public class BookOfCallingGui extends Screen {

public BookOfCallingItem.IItemModeSubset<?> mode;
public ItemMode mode;
public WorkAreaSize workAreaSize;

public BookOfCallingGui(BookOfCallingItem.IItemModeSubset<?> mode, WorkAreaSize workAreaSize) {
public BookOfCallingGui(ItemMode mode, WorkAreaSize workAreaSize) {
super(Component.literal(""));

this.mode = mode;
Expand Down Expand Up @@ -76,13 +80,19 @@ protected void init() {

//Item mode button
this.addRenderableWidget((new ExtendedButton(guiLeft - buttonWidth / 2, guiTop + 60, buttonWidth, 20,
Component.translatable(this.mode.getItemMode().getDescriptionId()), (b) -> {
this.mode = this.mode.next();
OccultismPackets.sendToServer(new MessageSetItemMode(this.mode.getItemMode().getValue()));
this.init();
Component.translatable(this.mode.translationKey()), (b) -> {
LocalPlayer player = Minecraft.getInstance().player;
ItemStack stack = player.getItemInHand(player.getUsedItemHand());
this.mode = stack.getItem() instanceof BookOfCallingItem ?
((BookOfCallingItem) stack.getItem()).nextItemMode(stack):null;
if(this.mode!=null)
{
OccultismPackets.sendToServer(new MessageSetItemMode(((BookOfCallingItem)stack.getItem()).modeValue(this.mode)));
this.init();
}
})));

boolean showSize = this.mode.getItemMode() == BookOfCallingItem.ItemMode.SET_BASE;
boolean showSize = this.mode.hasSize();
if (showSize) {
LabelWidget workAreaLabel = new LabelWidget(
guiLeft - 80, guiTop + 91, true, -1, 2, OccultismConstants.Color.WHITE).alignRight(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
package com.klikli_dev.occultism.common.item.spirit;

import com.klikli_dev.occultism.common.entity.job.CleanerJob;
import com.klikli_dev.occultism.common.item.spirit.calling.ItemMode;
import com.klikli_dev.occultism.common.item.spirit.calling.ItemModes;
import net.minecraft.world.item.ItemStack;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BookOfCallingCleanerItem extends BookOfCallingItem {
Expand All @@ -35,43 +39,7 @@ public BookOfCallingCleanerItem(Properties properties, String translationKeyBase
}

@Override
public IItemModeSubset<?> getItemModeSubset(ItemStack stack) {
ItemModeSubset subset = ItemModeSubset.get(ItemMode.get(this.getItemMode(stack)));
return subset != null ? subset : ItemModeSubset.SET_BASE;
}

public enum ItemModeSubset implements IItemModeSubset<ItemModeSubset> {
SET_BASE(ItemMode.SET_BASE),
SET_DEPOSIT(ItemMode.SET_DEPOSIT);

private static final Map<ItemMode, ItemModeSubset> lookup = new HashMap<>();

static {
for (ItemModeSubset subset : ItemModeSubset.values()) {
lookup.put(subset.getItemMode(), subset);
}
}

private final ItemMode itemMode;

ItemModeSubset(ItemMode itemMode) {
this.itemMode = itemMode;
}

//region Static Methods
public static ItemModeSubset get(ItemMode value) {
return lookup.get(value);
}

@Override
public ItemMode getItemMode() {
return this.itemMode;
}

@Override
public ItemModeSubset next() {
return values()[(this.ordinal() + 1) % values().length];
}
//endregion Static Methods
public List<ItemMode> getItemModes() {
return Arrays.asList(ItemModes.SET_BASE, ItemModes.SET_DEPOSIT);
}
}

0 comments on commit c892040

Please sign in to comment.