Added Charset compat to the redstone controller

TODO recipe
This commit is contained in:
malte0811 2018-08-05 16:49:55 +02:00
parent 7599b5cd31
commit 4fef9f6a04
10 changed files with 132 additions and 21 deletions

View File

@ -84,14 +84,18 @@ repositories {
dependencies {
deobfCompile 'net.industrial-craft:industrialcraft-2:2.8.+'
deobfCompile "blusunrize:ImmersiveEngineering:0.12-+"
deobfCompile "project-red-base:ProjectRed-1.12.2:4.9.1.92:Base"
runtime "project-red-integration:ProjectRed-1.12.2:4.9.1.92:integration"
runtime "forge-multipart-cbe:ForgeMultipart-1.12.2:2.5.0.69:universal"
runtime "codechicken:CodeChickenLib:1.12.2-3.2.1.349:universal"
runtime "codechicken:ChickenASM:1.12-1.0.2.7"
runtime "mrtjpcore:MrTJPCore-1.12.2:2.1.3.35:universal"
compileOnly "pl.asie.charset:charset:0.5.4.2.3:full"
//Project red and runtime dependencies
compileOnly "project-red-base:ProjectRed-1.12.2:4.9.1.92:Base"
//runtime "project-red-integration:ProjectRed-1.12.2:4.9.1.92:integration"
//runtime "forge-multipart-cbe:ForgeMultipart-1.12.2:2.5.0.69:universal"
//runtime "codechicken:CodeChickenLib:1.12.2-3.2.1.349:universal"
//runtime "codechicken:ChickenASM:1.12-1.0.2.7"
//runtime "mrtjpcore:MrTJPCore-1.12.2:2.1.3.35:universal"
//Tech Reborn
compileOnly "TechReborn:TechReborn-1.12:2.6.+:dev"
compileOnly "RebornCore:RebornCore-1.12:3.2.+:dev"
//Others
compileOnly 'com.elytradev:mirage:2.0.1-SNAPSHOT'
compileOnly "mezz.jei:jei_1.12:4.+"
compileOnly "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.8.460"

View File

@ -16,11 +16,17 @@
package malte0811.industrialWires.blocks.controlpanel;
import malte0811.industrialWires.compat.Compat;
import malte0811.industrialWires.compat.CompatCapabilities.Charset;
import mrtjp.projectred.api.IBundledTile;
import mrtjp.projectred.api.ProjectRedAPI;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
@Optional.Interface(iface = "mrtjp.projectred.api.IBundledTile", modid = ProjectRedAPI.modIDCore)
public class TileEntityRSPanelOthers extends TileEntityRSPanel implements IBundledTile {
@ -41,7 +47,7 @@ public class TileEntityRSPanelOthers extends TileEntityRSPanel implements IBundl
public void updateInput() {
byte[] data = new byte[16];
for (EnumFacing f:EnumFacing.VALUES) {
byte[] tmp = Compat.getBundledRS.getBundledInput(world, pos, f);
byte[] tmp = Compat.getBundledRS.run(world, pos, f);
if (tmp!=null) {
for (int i = 0;i<16;i++) {
if (tmp[i]>data[i]) {
@ -55,6 +61,22 @@ public class TileEntityRSPanelOthers extends TileEntityRSPanel implements IBundl
@Override
protected void updateOutput() {
world.notifyNeighborsOfStateChange(pos, getBlockType(), true);
Compat.updateBundledRS.run(world, pos, null);
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability==Charset.EMITTER_CAP) {
return Charset.EMITTER_CAP.cast(()->Arrays.copyOf(out, 16));
} else if (capability==Charset.RECEIVER_CAP) {
return Charset.RECEIVER_CAP.cast(this::updateInput);
}
return null;
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability==Charset.EMITTER_CAP||capability==Charset.RECEIVER_CAP;
}
}

View File

@ -25,6 +25,7 @@ import ic2.api.energy.tile.IEnergyTile;
import ic2.api.item.IBoxable;
import ic2.api.item.IC2Items;
import ic2.core.block.TileEntityBlock;
import malte0811.industrialWires.compat.CompatCapabilities.Charset;
import malte0811.industrialWires.hv.MarxOreHandler;
import malte0811.industrialWires.mech_mb.MechPartCommutator;
import mrtjp.projectred.api.ProjectRedAPI;
@ -32,11 +33,14 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.gen.structure.template.Template;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import pl.asie.charset.api.wires.IBundledEmitter;
import pl.asie.charset.api.wires.IBundledReceiver;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -45,6 +49,9 @@ import java.util.function.BiFunction;
import java.util.function.Consumer;
public class Compat {
public static final String IC2_ID = "ic2";
public static final String CRAFTTWEAKER_ID = "crafttweaker";
public static final String CHARSET_ID = "charset";
public static BiFunction<ItemStack, Template.BlockInfo, ItemStack> stackFromInfo = (s, i)->s;
static Consumer<MarxOreHandler.OreInfo> addMarx = (o) -> {
};
@ -54,10 +61,12 @@ public class Compat {
};
public static Consumer<TileEntity> unloadIC2Tile = te -> {
};
public static IBundledRSGetter getBundledRS = (w, p, f) -> new byte[16];
public static IBlockAction<EnumFacing, byte[]> getBundledRS = (w, p, f) -> new byte[16];
public static IBlockAction<Void, Void> updateBundledRS = (w, p, f) -> null;
public static boolean enableOtherRS = false;
private static Map<String, Class<? extends CompatModule>> modules = ImmutableMap.of("ic2", CompatIC2.class,
"crafttweaker", CompatCT.class, ProjectRedAPI.modIDCore, CompatProjectRed.class);
private static Map<String, Class<? extends CompatModule>> modules = ImmutableMap.of(IC2_ID, CompatIC2.class,
CRAFTTWEAKER_ID, CompatCT.class, ProjectRedAPI.modIDCore, CompatProjectRed.class,
CHARSET_ID, CompatCharset.class);
private static Method preInit;
private static Method init;
@ -162,10 +171,10 @@ public class Compat {
@Override
public void init() {
super.init();
IBundledRSGetter old = getBundledRS;
IBlockAction<EnumFacing, byte[]> oldGet = getBundledRS;
enableOtherRS = true;
getBundledRS = (w, p, f) -> {
byte[] oldIn = old.getBundledInput(w, p, f);
byte[] oldIn = oldGet.run(w, p, f);
byte[] prIn = ProjectRedAPI.transmissionAPI.getBundledInput(w, p, f);
if (prIn!=null) {
for (int i = 0; i < 16; i++) {
@ -174,6 +183,51 @@ public class Compat {
}
return oldIn;
};
IBlockAction<Void, Void> oldUpdate = updateBundledRS;
updateBundledRS = (w, p, f)-> {
oldUpdate.run(w, p, f);
w.notifyNeighborsOfStateChange(p, w.getBlockState(p).getBlock(), true);
return null;
};
}
}
public static class CompatCharset extends CompatModule {
@Override
public void init() {
super.init();
IBlockAction<EnumFacing, byte[]> old = getBundledRS;
enableOtherRS = true;
getBundledRS = (w, p, f) -> {
byte[] oldIn = old.run(w, p, f);
TileEntity te = w.getTileEntity(p.offset(f));
if (te!=null && te.hasCapability(Charset.EMITTER_CAP, f.getOpposite())) {
IBundledEmitter emitter = te.getCapability(Charset.EMITTER_CAP, f.getOpposite());
assert emitter!=null;
byte[] charIn = emitter.getBundledSignal();
if (charIn!=null) {
for (int i = 0;i<16;i++) {
if (charIn[i]>oldIn[i]) {
oldIn[i] = charIn[i];
}
}
}
}
return oldIn;
};
IBlockAction<Void, Void> oldUpdate = updateBundledRS;
updateBundledRS = (w, p, __)-> {
oldUpdate.run(w, p, __);
for (EnumFacing face : EnumFacing.VALUES) {
TileEntity te = w.getTileEntity(p.offset(face.getOpposite()));
if (te != null && te.hasCapability(Charset.RECEIVER_CAP, face)) {
IBundledReceiver receiver = te.getCapability(Charset.RECEIVER_CAP, face);
assert receiver != null;
receiver.onBundledInputChange();
}
}
return null;
};
}
}
}

View File

@ -0,0 +1,30 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.compat;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import pl.asie.charset.api.wires.IBundledEmitter;
import pl.asie.charset.api.wires.IBundledReceiver;
public class CompatCapabilities {
public static class Charset {
@CapabilityInject(IBundledEmitter.class)
public static Capability<IBundledEmitter> EMITTER_CAP;
@CapabilityInject(IBundledReceiver.class)
public static Capability<IBundledReceiver> RECEIVER_CAP;
}
}

View File

@ -15,10 +15,9 @@
package malte0811.industrialWires.compat;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface IBundledRSGetter {
byte[] getBundledInput(World w, BlockPos pos, EnumFacing f);
public interface IBlockAction<P, R> {
R run(World w, BlockPos pos, P f);
}

View File

@ -43,7 +43,7 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implemen
}
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
int l = getLength(inv);
return l > 0;
}

View File

@ -31,7 +31,7 @@ import javax.annotation.Nullable;
public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
boolean found = false;
int foundX = -1;
int foundY = -1;

View File

@ -29,11 +29,12 @@ import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipeKeyLock extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
return getLockId(inv) != 0;
}

View File

@ -27,6 +27,7 @@ import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static malte0811.industrialWires.util.NBTKeys.*;
@ -38,7 +39,7 @@ public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements
}
@Override
public boolean matches(@Nonnull InventoryCrafting inv, World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
return isValid(inv);
}

View File

@ -112,7 +112,7 @@
"model": "industrialwires:block/panel_creator.obj"
//Doesn't matter, this will be overridden in code
},
"other_rs_wires": {
"inventory,type=other_rs_wires": {
"model": "cube_all",
"textures": {"all": "industrialwires:blocks/rs_panel_others"}
}