Add custom TunnelType registration API
This commit is contained in:
@@ -37,6 +37,7 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -277,4 +278,9 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry {
|
||||
private void addNewAttunement(final IItemDefinition definition, final TunnelType type) {
|
||||
definition.maybeStack(1).ifPresent(definitionStack -> this.addNewAttunement(definitionStack, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunnelType registerTunnelType(@NotNull String enumName, @NotNull ItemStack partStack) {
|
||||
return TunnelType.registerTunnelType(enumName, partStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,7 @@ package appeng.parts.p2p;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
@@ -185,8 +180,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
}
|
||||
|
||||
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem(is);
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard mc) {
|
||||
final NBTTagCompound data = mc.getData(is);
|
||||
|
||||
final ItemStack newType = new ItemStack(data);
|
||||
@@ -208,8 +202,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
if (newBus instanceof PartP2PTunnel newTunnel) {
|
||||
|
||||
if (pasteAsOutput) {
|
||||
newTunnel.setOutput(true);
|
||||
@@ -233,56 +226,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
mc.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
|
||||
} else if (tt != null) // attunement
|
||||
{
|
||||
final ItemStack newType;
|
||||
|
||||
final IParts parts = AEApi.instance().definitions().parts();
|
||||
|
||||
switch (tt) {
|
||||
case LIGHT:
|
||||
newType = parts.p2PTunnelLight().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case FE_POWER:
|
||||
newType = parts.p2PTunnelFE().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case GTEU_POWER:
|
||||
newType = parts.p2PTunnelGTEU().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case FLUID:
|
||||
newType = parts.p2PTunnelFluids().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case IC2_POWER:
|
||||
newType = parts.p2PTunnelEU().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
newType = parts.p2PTunnelItems().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case ME:
|
||||
newType = parts.p2PTunnelME().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case REDSTONE:
|
||||
newType = parts.p2PTunnelRedstone().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
/*
|
||||
* case COMPUTER_MESSAGE:
|
||||
* for( ItemStack stack : parts.p2PTunnelOpenComputers().maybeStack( 1 ).asSet() )
|
||||
* {
|
||||
* newType = stack;
|
||||
* }
|
||||
* break;
|
||||
*/
|
||||
|
||||
default:
|
||||
newType = ItemStack.EMPTY;
|
||||
break;
|
||||
}
|
||||
final ItemStack newType = tt.getPartItemStack();
|
||||
|
||||
if (!newType.isEmpty() && !ItemStack.areItemsEqual(newType, this.getItemStack())) {
|
||||
final boolean oldOutput = this.isOutput();
|
||||
@@ -299,8 +243,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
if (newBus instanceof PartP2PTunnel newTunnel) {
|
||||
newTunnel.setOutput(oldOutput);
|
||||
|
||||
try {
|
||||
@@ -333,12 +276,11 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
}
|
||||
|
||||
final ItemStack is = player.inventory.getCurrentItem();
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard mc) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
final NBTTagCompound data = mc.getData(is);
|
||||
final short storedFrequency = data.getShort("freq");
|
||||
|
||||
@@ -365,8 +307,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
if (newBus instanceof PartP2PTunnel newTunnel) {
|
||||
newTunnel.setOutput(false);
|
||||
newTunnel.getProxy().getP2P().updateFreq(newTunnel, newFreq);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user