Skip to content

Commit

Permalink
Cleaning up the ME GUIs (Items+Fluids) (AppliedEnergistics#5105)
Browse files Browse the repository at this point in the history
Completely refactor all UI. Introduce JSON based definitions for screens (can be overridden in resource packs). Unifies fluid and item terminal UI code. Serializes item data from server->client using "share tags" (i.e. don't include the content of bags if they support that), and no longer synchronize capability data to the client. Use "serial numbers" to refer back to items on the server when a player interacts with items in terminals. This should fix AppliedEnergistics#5083 "for good" while still using less network bandwidth. It should also fix AppliedEnergistics#5199 because serialization of items into packets is rewritten and now uses a length-prefix, reducing the chance for corrupted packets due to very long item NBT data.
Rewrote crafting status / network status to use custom packets rather than reusing the inventory sync packets.

Also implements AppliedEnergistics#3787, AppliedEnergistics#3922

Also adds:
    Start using share tags / stop sending caps to clients, which should reduce bandwidth usage when opening terminals
    Consider missing items on "shift-clickicking" recipes into the crafting terminal from JEI
    Adds tooltip indicating which upgrades are compatible to the upgrade panel for various machines
    Adds information on how priority works to the priority screen
    Use standard slots for the player inventory, which should fix most inventory sorting mods moving the hotbar into the main inventory when sorting the player inventory within an AE2 screen.
    Add clickable "show recipes" areas that open the appropriate JEI category to the inscriber and grindstone
  • Loading branch information
shartte authored May 10, 2021
1 parent a20c5f9 commit fca741b
Show file tree
Hide file tree
Showing 452 changed files with 16,271 additions and 10,776 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
!.travis.yml

# include markdowns
!README.md
!*.md
!LICENSE

# include sourcecode except generated
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1")
testImplementation("org.assertj:assertj-core:3.19.0")
testImplementation("com.google.guava:guava-testlib:21.0")
testImplementation("org.mockito:mockito-junit-jupiter:3.9.0")
testImplementation("org.mockito:mockito-inline:3.9.0")

// Annotation Processors
annotationProcessor 'org.spongepowered:mixin:0.8:processor'
Expand Down
15 changes: 11 additions & 4 deletions src/api/java/appeng/api/config/SecurityPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import java.util.Locale;

import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;

/**
* Represent the security systems basic permissions, these are not for anti-griefing, they are part of the mod as a
* gameplay feature.
Expand Down Expand Up @@ -59,11 +62,15 @@ public enum SecurityPermissions {

private final String translationKey = "gui.appliedenergistics2.security." + this.name().toLowerCase(Locale.ROOT);

public String getTranslatedName() {
return this.translationKey + ".name";
private final ITextComponent displayName = new TranslationTextComponent(this.translationKey + ".name");

private final ITextComponent displayHint = new TranslationTextComponent(this.translationKey + ".tip");

public ITextComponent getDisplayName() {
return this.displayName;
}

public String getTranslatedTip() {
return this.translationKey + ".tip";
public ITextComponent getDisplayHint() {
return this.displayHint;
}
}
16 changes: 13 additions & 3 deletions src/api/java/appeng/api/config/Upgrades.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,29 @@ public enum Upgrades {
/**
* Gold Tier Upgrades.
*/
CAPACITY(0), REDSTONE(0), CRAFTING(0),
CAPACITY("item.appliedenergistics2.capacity_card", 0),
REDSTONE("item.appliedenergistics2.redstone_card", 0),
CRAFTING("item.appliedenergistics2.crafting_card", 0),

/**
* Diamond Tier Upgrades.
*/
FUZZY(1), SPEED(1), INVERTER(1);
FUZZY("item.appliedenergistics2.fuzzy_card", 1),
SPEED("item.appliedenergistics2.speed_card", 1),
INVERTER("item.appliedenergistics2.inverter_card", 1);

private final int tier;
private final ITextComponent displayName;
private final List<Supported> supported = new ArrayList<>();
private List<ITextComponent> supportedTooltipLines;

Upgrades(final int tier) {
Upgrades(final String translationKey, final int tier) {
this.tier = tier;
this.displayName = new TranslationTextComponent(translationKey);
}

public ITextComponent getDisplayName() {
return displayName;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/api/java/appeng/api/definitions/IdHelper.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2021 TeamAppliedEnergistics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package appeng.api.definitions;

import net.minecraft.util.ResourceLocation;
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/appeng/api/features/INetworkEncodable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface INetworkEncodable {
*
* @param item item
*
* @return string key of item
* @return the encoded encryption key or an empty string if none is encoded
*/
String getEncryptionKey(ItemStack item);

Expand Down
14 changes: 14 additions & 0 deletions src/api/java/appeng/api/implementations/IUpgradeableHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@

package appeng.api.implementations;

import java.util.Objects;

import javax.annotation.Nonnull;

import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.IItemHandler;

import appeng.api.config.Upgrades;
import appeng.api.implementations.tiles.ISegmentedInventory;
Expand All @@ -42,4 +47,13 @@ public interface IUpgradeableHost extends IConfigurableObject, ISegmentedInvento
* @return tile entity
*/
TileEntity getTile();

/**
* @return The inventory used to store the upgrade cards.
*/
@Nonnull
default IItemHandler getUpgradeInventory() {
return Objects.requireNonNull(getInventoryByName("upgrades"));
}

}
7 changes: 6 additions & 1 deletion src/api/java/appeng/api/networking/IGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public interface IGrid {
* @param iface face
*
* @return the IGridCache you requested.
*
* TODO: 1.17 breaking change: throw if iface is not a registered grid cache to fulfil contract TODO: 1.17
* breaking chance: make the parameter Class<C>
*/
@Nonnull
<C extends IGridCache> C getCache(@Nonnull Class<? extends IGridCache> iface);
Expand All @@ -51,6 +54,8 @@ public interface IGrid {
* @param ev - event to post
*
* @return returns ev back to original poster
*
* TODO: Breaking change in 1.17: T extends MENetworkEvent and return T
*/
@Nonnull
MENetworkEvent postEvent(@Nonnull MENetworkEvent ev);
Expand All @@ -60,7 +65,7 @@ public interface IGrid {
*
* @param ev event to post
*
* @return returns ev back to original poster
* @return returns ev back to original poster TODO: Breaking change in 1.17: T extends MENetworkEvent and return T
*/
@Nonnull
MENetworkEvent postEventTo(@Nonnull IGridNode node, @Nonnull MENetworkEvent ev);
Expand Down
16 changes: 16 additions & 0 deletions src/api/java/appeng/api/parts/PartItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@
package appeng.api.parts;

public enum PartItemStack {
/**
* A stack that is used when someone uses the creative mode middle click to "pick" the part.
*/
PICK,

/**
* A stack that is dropped when the part is being broken as part of the cable bus.
*/
BREAK,

/**
* A stack that is dropped when the part is being hit with a wrench.
*/
WRENCH,

/**
* A stack that uniquely identifies the part when it is sent over the network. Only the id of the item contained in
* the stack is sent over the network.
*/
NETWORK,

/**
* A stack that uniquely identifies the part when it is stored to disk as part of the chunk.
*/
WORLD
}
14 changes: 0 additions & 14 deletions src/api/java/appeng/api/storage/IStorageChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

package appeng.api.storage;

import java.io.IOException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand All @@ -43,8 +41,6 @@ public interface IStorageChannel<T extends IAEStack<T>> {
*
* E.g. used by IO Ports to transfer 1000 mB, not 1 mB to match the item channel transferring a full bucket per
* operation.
*
* @return
*/
default int transferFactor() {
return 1;
Expand All @@ -62,8 +58,6 @@ default int getUnitsPerByte() {

/**
* Create a new {@link IItemList} of the specific type.
*
* @return
*/
@Nonnull
IItemList<T> createList();
Expand All @@ -82,19 +76,11 @@ default int getUnitsPerByte() {
@Nullable
T createStack(@Nonnull Object input);

/**
* @param input
* @return
* @throws IOException
*/
@Nullable
T readFromPacket(@Nonnull PacketBuffer input);

/**
* create from nbt data
*
* @param nbt
* @return
*/
@Nullable
T createFromNBT(@Nonnull CompoundNBT nbt);
Expand Down
1 change: 0 additions & 1 deletion src/api/java/appeng/api/storage/IStorageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public interface IStorageHelper {
* @param channel The channel type, must be a subtype of {@link IStorageChannel}
* @param factory An instance implementing the channel, must be be an instance of channel
*/
@Nonnull
<T extends IAEStack<T>, C extends IStorageChannel<T>> void registerStorageChannel(@Nonnull Class<C> channel,
@Nonnull C factory);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/block/AEBaseTileBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public IOrientable getOrientable(final IBlockReader w, final BlockPos pos) {

/**
* Returns the BlockState based on the given BlockState while considering the state of the given TileEntity.
*
* <p>
* If the given TileEntity is not of the right type for this block, the state is returned unchanged, this is also
* the case if the given block state does not belong to this block.
*/
Expand All @@ -277,7 +277,7 @@ public final BlockState getTileEntityBlockState(BlockState current, TileEntity t
/**
* Reimplement this in subclasses to allow tile-entities to update the state of their block when their own state
* changes.
*
* <p>
* It is guaranteed that te is not-null and the block of the given block state is this exact block instance.
*/
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, T te) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.CraftingCPUContainer;
import appeng.container.me.crafting.CraftingCPUContainer;
import appeng.tile.crafting.CraftingTileEntity;
import appeng.util.InteractionUtil;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/block/misc/CellWorkbenchBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.CellWorkbenchContainer;
import appeng.tile.misc.CellWorkbenchTileEntity;
import appeng.util.InteractionUtil;
Expand All @@ -51,7 +52,7 @@ public ActionResultType onActivated(final World w, final BlockPos pos, final Pla
final CellWorkbenchTileEntity tg = this.getTileEntity(w, pos);
if (tg != null) {
if (!w.isRemote()) {
CellWorkbenchContainer.open(p, ContainerLocator.forTileEntity(tg));
ContainerOpener.openContainer(CellWorkbenchContainer.TYPE, p, ContainerLocator.forTileEntity(tg));
}
return ActionResultType.func_233537_a_(w.isRemote());
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/appeng/block/misc/ChargerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import appeng.core.AppEng;
import appeng.tile.misc.ChargerTileEntity;
import appeng.util.InteractionUtil;
import appeng.util.Platform;

public class ChargerBlock extends AEBaseTileBlock<ChargerTileEntity> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/block/misc/InscriberBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public InscriberBlock(Properties props) {
@Override
public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
return 2; // FIXME validate this. a) possibly not required because of getShape b) value
// range. was 2 in 1.10
// range. was 2 in 1.10
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/appeng/block/misc/TinyTNTBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -41,7 +40,6 @@
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

import appeng.block.AEBaseBlock;
import appeng.entity.TinyTNTPrimedEntity;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/block/misc/VibrationChamberBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public ActionResultType onActivated(final World w, final BlockPos pos, final Pla
return ActionResultType.PASS;
}

if (w.isRemote()) {
if (!w.isRemote()) {
final VibrationChamberTileEntity tc = this.getTileEntity(w, pos);
if (tc != null && !InteractionUtil.isInAlternateUseMode(player)) {
if (tc != null) {
ContainerOpener.openContainer(VibrationChamberContainer.TYPE, player,
ContainerLocator.forTileEntitySide(tc, hit.getFace()));
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/appeng/block/paint/PaintSplotchesBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import appeng.block.AEBaseTileBlock;
import appeng.tile.misc.PaintSplotchesTileEntity;
import appeng.util.Platform;

public class PaintSplotchesBlock extends AEBaseTileBlock<PaintSplotchesTileEntity> {
public PaintSplotchesBlock() {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/appeng/client/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import appeng.api.parts.CableRenderMode;
import appeng.block.AEBaseBlock;
import appeng.client.gui.style.StyleManager;
import appeng.client.render.effects.EnergyParticleData;
import appeng.client.render.effects.LightningArcFX;
import appeng.client.render.effects.LightningFX;
Expand All @@ -58,6 +59,13 @@ public class ClientHelper extends ServerHelper {

private final EnumMap<ActionKey, KeyBinding> bindings = new EnumMap<>(ActionKey.class);

public ClientHelper() {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft != null) {
StyleManager.initialize(minecraft.getResourceManager());
}
}

public void clientInit() {
MinecraftForge.EVENT_BUS.addListener(this::postPlayerRender);
MinecraftForge.EVENT_BUS.addListener(this::wheelEvent);
Expand Down
Loading

0 comments on commit fca741b

Please sign in to comment.