Removed reliance on PartType from code outside of Bootstrapping,

and restored ability to group different supported items on
Upgrade Card tooltips.
This commit is contained in:
Sebastian Hartte
2020-07-01 00:33:15 +02:00
parent 400fcdb633
commit c67dba2f13
18 changed files with 368 additions and 596 deletions
+2 -75
View File
@@ -18,31 +18,24 @@
package appeng.items.parts;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType;
import appeng.api.AEApi;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartItem;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
public class PartItem<T extends IPart> extends AEBaseItem implements IPartItem<T>, IItemGroup {
private final PartType type;
public class PartItem<T extends IPart> extends AEBaseItem implements IPartItem<T> {
private final Function<ItemStack, T> factory;
public PartItem(Properties properties, PartType type, Function<ItemStack, T> factory) {
public PartItem(Properties properties, Function<ItemStack, T> factory) {
super(properties);
this.type = type;
this.factory = factory;
}
@@ -58,75 +51,9 @@ public class PartItem<T extends IPart> extends AEBaseItem implements IPartItem<T
context.getHand(), context.getWorld());
}
public PartType getType() {
return type;
}
@Override
public T createPart(ItemStack is) {
return factory.apply(is);
}
private static PartType getTypeByStack(ItemStack is) {
if (is.getItem() instanceof PartItem) {
return ((PartItem<?>) is.getItem()).getType();
}
return PartType.INVALID_TYPE;
}
@Nullable
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
boolean importBus = false;
boolean importBusFluids = false;
boolean exportBus = false;
boolean exportBusFluids = false;
boolean group = false;
final PartType u = getTypeByStack(is);
for (final ItemStack stack : others) {
if (stack.getItem() == this) {
final PartType pt = getTypeByStack(stack);
switch (pt) {
case IMPORT_BUS:
importBus = true;
if (u == pt) {
group = true;
}
break;
case FLUID_IMPORT_BUS:
importBusFluids = true;
if (u == pt) {
group = true;
}
break;
case EXPORT_BUS:
exportBus = true;
if (u == pt) {
group = true;
}
break;
case FLUID_EXPORT_BUS:
exportBusFluids = true;
if (u == pt) {
group = true;
}
break;
default:
}
}
}
if (group && importBus && exportBus && (u == PartType.IMPORT_BUS || u == PartType.EXPORT_BUS)) {
return GuiText.IOBuses.getTranslationKey();
}
if (group && importBusFluids && exportBusFluids
&& (u == PartType.FLUID_IMPORT_BUS || u == PartType.FLUID_EXPORT_BUS)) {
return GuiText.IOBusesFluids.getTranslationKey();
}
return null;
}
}