-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin work on adding a Portable Cell Workbench
- Loading branch information
Showing
15 changed files
with
610 additions
and
5 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
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.21.1 2024-11-15T19:31:29.757213749 Language | ||
01c5e0e544a51a97c1494a283b0c34a0e73b3f14 assets/megacells/lang/en_us.json | ||
// 1.21.1 2024-11-15T20:14:53.378044013 Language | ||
a77898c0ee75796bccabca2cf157f495702102d1 assets/megacells/lang/en_us.json |
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
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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/megacells/models/item/portable_cell_workbench.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "megacells:item/portable_cell_workbench" | ||
} | ||
} |
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
111 changes: 111 additions & 0 deletions
111
src/main/java/gripe/_90/megacells/client/screen/PortableCellWorkbenchScreen.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,111 @@ | ||
package gripe._90.megacells.client.screen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import appeng.api.config.ActionItems; | ||
import appeng.api.config.CopyMode; | ||
import appeng.api.config.FuzzyMode; | ||
import appeng.api.config.Settings; | ||
import appeng.api.stacks.AEItemKey; | ||
import appeng.api.stacks.GenericStack; | ||
import appeng.client.gui.Icon; | ||
import appeng.client.gui.implementations.UpgradeableScreen; | ||
import appeng.client.gui.style.ScreenStyle; | ||
import appeng.client.gui.widgets.ActionButton; | ||
import appeng.client.gui.widgets.SettingToggleButton; | ||
import appeng.client.gui.widgets.ToggleButton; | ||
import appeng.core.definitions.AEItems; | ||
import appeng.core.localization.GuiText; | ||
|
||
import gripe._90.megacells.menu.PortableCellWorkbenchMenu; | ||
|
||
/** | ||
* See {@link appeng.client.gui.implementations.CellWorkbenchScreen} | ||
*/ | ||
public class PortableCellWorkbenchScreen extends UpgradeableScreen<PortableCellWorkbenchMenu> { | ||
private final ToggleButton copyMode; | ||
private final SettingToggleButton<FuzzyMode> fuzzyMode; | ||
|
||
public PortableCellWorkbenchScreen( | ||
PortableCellWorkbenchMenu menu, Inventory playerInventory, Component title, ScreenStyle style) { | ||
super(menu, playerInventory, title, style); | ||
fuzzyMode = addToLeftToolbar(new SettingToggleButton<>( | ||
Settings.FUZZY_MODE, | ||
FuzzyMode.IGNORE_ALL, | ||
(button, backwards) -> menu.setCellFuzzyMode(button.getNextValue(backwards)))); | ||
addToLeftToolbar(new ActionButton(ActionItems.COG, act -> menu.partition())); | ||
addToLeftToolbar(new ActionButton(ActionItems.CLOSE, act -> menu.clear())); | ||
copyMode = addToLeftToolbar(new ToggleButton( | ||
Icon.COPY_MODE_ON, | ||
Icon.COPY_MODE_OFF, | ||
GuiText.CopyMode.text(), | ||
GuiText.CopyModeDesc.text(), | ||
act -> menu.nextWorkBenchCopyMode())); | ||
} | ||
|
||
@Override | ||
protected void updateBeforeRender() { | ||
super.updateBeforeRender(); | ||
copyMode.setState(menu.getCopyMode() == CopyMode.CLEAR_ON_REMOVE); | ||
fuzzyMode.set(menu.getFuzzyMode()); | ||
fuzzyMode.setVisibility(menu.getUpgrades().isInstalled(AEItems.FUZZY_CARD)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected List<Component> getTooltipFromContainerItem(@NotNull ItemStack stack) { | ||
var cell = getMenu().getWorkbenchItem(); | ||
|
||
if (cell.isEmpty()) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
if (cell == stack) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
var genericStack = GenericStack.unwrapItemStack(stack); | ||
var what = genericStack != null ? genericStack.what() : AEItemKey.of(stack); | ||
|
||
if (what == null) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
var configInventory = getMenu().getHost().getCell().getConfigInventory(cell); | ||
|
||
if (!configInventory.isSupportedType(what.getType())) { | ||
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack)); | ||
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED)); | ||
return lines; | ||
} | ||
|
||
var filter = configInventory.getFilter(); | ||
|
||
if (filter != null) { | ||
var anySlotMatches = false; | ||
|
||
for (var i = 0; i < configInventory.size(); i++) { | ||
if (configInventory.isAllowedIn(i, what)) { | ||
anySlotMatches = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!anySlotMatches) { | ||
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack)); | ||
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED)); | ||
return lines; | ||
} | ||
} | ||
|
||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/gripe/_90/megacells/item/cell/PortableCellWorkbenchItem.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,45 @@ | ||
package gripe._90.megacells.item.cell; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
|
||
import appeng.api.implementations.menuobjects.IMenuItem; | ||
import appeng.api.implementations.menuobjects.ItemMenuHost; | ||
import appeng.items.AEBaseItem; | ||
import appeng.menu.MenuOpener; | ||
import appeng.menu.locator.ItemMenuHostLocator; | ||
import appeng.menu.locator.MenuLocators; | ||
|
||
import gripe._90.megacells.definition.MEGAMenus; | ||
|
||
public class PortableCellWorkbenchItem extends AEBaseItem implements IMenuItem { | ||
public PortableCellWorkbenchItem(Properties properties) { | ||
super(properties.stacksTo(1)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ItemMenuHost<?> getMenuHost(Player player, ItemMenuHostLocator locator, @Nullable BlockHitResult hitResult) { | ||
return new PortableCellWorkbenchMenuHost(this, player, locator); | ||
} | ||
|
||
@ParametersAreNonnullByDefault | ||
@NotNull | ||
@Override | ||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { | ||
if (!level.isClientSide()) { | ||
MenuOpener.open(MEGAMenus.PORTABLE_CELL_WORKBENCH, player, MenuLocators.forHand(player, hand)); | ||
} | ||
|
||
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide()); | ||
} | ||
} |
Oops, something went wrong.