mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Add charset bundled cable integration
- Bump MinecraftForge version so we don't crash on load. Oh boy, all the deprecation warnings. - Inject IBundledEmitter and IBundledReceiver capabilities onto all TileGenerics. - Register a IBundledRedstoneProvider instance for IBundledEmitter.
This commit is contained in:
parent
0685be6bfa
commit
093132533d
@ -28,7 +28,7 @@ group = "org.squiddev"
|
|||||||
archivesBaseName = "cc-tweaked"
|
archivesBaseName = "cc-tweaked"
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "1.12.2-14.23.2.2634"
|
version = "1.12.2-14.23.4.2749"
|
||||||
runDir = "run"
|
runDir = "run"
|
||||||
replace '${version}', project.version
|
replace '${version}', project.version
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ repositories {
|
|||||||
name = "squiddev"
|
name = "squiddev"
|
||||||
url = "https://dl.bintray.com/squiddev/maven"
|
url = "https://dl.bintray.com/squiddev/maven"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ivy { artifactPattern "https://asie.pl/files/mods/Charset/LibOnly/[module]-[revision](-[classifier]).[ext]" }
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
@ -60,7 +62,10 @@ configurations {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
deobfProvided "mezz.jei:jei_1.12.2:4.8.5.159:api"
|
deobfProvided "mezz.jei:jei_1.12.2:4.8.5.159:api"
|
||||||
|
deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
||||||
|
|
||||||
runtime "mezz.jei:jei_1.12.2:4.8.5.159"
|
runtime "mezz.jei:jei_1.12.2:4.8.5.159"
|
||||||
|
|
||||||
shade 'org.squiddev:Cobalt:0.3.2'
|
shade 'org.squiddev:Cobalt:0.3.2'
|
||||||
|
|
||||||
testCompile 'junit:junit:4.11'
|
testCompile 'junit:junit:4.11'
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.integration.charset;
|
||||||
|
|
||||||
|
import dan200.computercraft.shared.common.TileGeneric;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||||
|
import pl.asie.charset.api.wires.IBundledEmitter;
|
||||||
|
import pl.asie.charset.api.wires.IBundledReceiver;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER;
|
||||||
|
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_RECEIVER;
|
||||||
|
|
||||||
|
final class BundledCapabilityProvider implements ICapabilityProvider
|
||||||
|
{
|
||||||
|
private final TileGeneric tile;
|
||||||
|
private IBundledReceiver receiver;
|
||||||
|
private IBundledEmitter[] emitters;
|
||||||
|
|
||||||
|
BundledCapabilityProvider( TileGeneric tile )
|
||||||
|
{
|
||||||
|
this.tile = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable EnumFacing side )
|
||||||
|
{
|
||||||
|
return capability == CAPABILITY_EMITTER || capability == CAPABILITY_RECEIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing side )
|
||||||
|
{
|
||||||
|
if( capability == CAPABILITY_RECEIVER )
|
||||||
|
{
|
||||||
|
IBundledReceiver receiver = this.receiver;
|
||||||
|
if( receiver == null ) receiver = this.receiver = tile::onNeighbourChange;
|
||||||
|
|
||||||
|
return CAPABILITY_RECEIVER.cast( receiver );
|
||||||
|
}
|
||||||
|
else if( capability == CAPABILITY_EMITTER )
|
||||||
|
{
|
||||||
|
IBundledEmitter[] emitters = this.emitters;
|
||||||
|
if( emitters == null ) emitters = this.emitters = new IBundledEmitter[7];
|
||||||
|
|
||||||
|
int index = side == null ? 6 : side.getIndex();
|
||||||
|
IBundledEmitter emitter = emitters[index];
|
||||||
|
if( emitter == null )
|
||||||
|
{
|
||||||
|
if( side == null )
|
||||||
|
{
|
||||||
|
emitter = emitters[index] = () -> {
|
||||||
|
int flags = 0;
|
||||||
|
for( EnumFacing facing : EnumFacing.VALUES ) flags |= tile.getBundledRedstoneOutput( facing );
|
||||||
|
return toBytes( flags );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emitter = emitters[index] = () -> toBytes( tile.getBundledRedstoneOutput( side ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
return CAPABILITY_EMITTER.cast( emitter );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] toBytes( int flag )
|
||||||
|
{
|
||||||
|
byte[] channels = new byte[16];
|
||||||
|
for( int i = 0; i < 16; i++ ) channels[i] = (flag & (1 << i)) == 0 ? (byte) 0 : 15;
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.integration.charset;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER;
|
||||||
|
|
||||||
|
public class BundledRedstoneProvider implements IBundledRedstoneProvider
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
||||||
|
{
|
||||||
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
|
if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1;
|
||||||
|
|
||||||
|
byte[] signal = tile.getCapability( CAPABILITY_EMITTER, side ).getBundledSignal();
|
||||||
|
if( signal == null ) return -1;
|
||||||
|
|
||||||
|
int flag = 0;
|
||||||
|
for( int i = 0; i < signal.length; i++ ) flag |= signal[i] > 0 ? (1 << i) : 0;
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.integration.charset;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
|
import dan200.computercraft.shared.common.TileGeneric;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||||
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import pl.asie.charset.api.wires.IBundledEmitter;
|
||||||
|
import pl.asie.charset.api.wires.IBundledReceiver;
|
||||||
|
|
||||||
|
public final class IntegrationCharset
|
||||||
|
{
|
||||||
|
private static final ResourceLocation CAPABILITY_KEY = new ResourceLocation( ComputerCraft.MOD_ID, "charset" );
|
||||||
|
|
||||||
|
@CapabilityInject( IBundledEmitter.class )
|
||||||
|
public static final Capability<IBundledEmitter> CAPABILITY_EMITTER = null;
|
||||||
|
|
||||||
|
@CapabilityInject( IBundledReceiver.class )
|
||||||
|
public static final Capability<IBundledReceiver> CAPABILITY_RECEIVER = null;
|
||||||
|
|
||||||
|
private IntegrationCharset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register()
|
||||||
|
{
|
||||||
|
if( CAPABILITY_EMITTER == null || CAPABILITY_RECEIVER == null ) return;
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register( new IntegrationCharset() );
|
||||||
|
ComputerCraftAPI.registerBundledRedstoneProvider( new BundledRedstoneProvider() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event)
|
||||||
|
{
|
||||||
|
TileEntity tile = event.getObject();
|
||||||
|
if(tile instanceof TileGeneric)
|
||||||
|
{
|
||||||
|
event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ import dan200.computercraft.shared.computer.core.*;
|
|||||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||||
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
||||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||||
|
import dan200.computercraft.shared.integration.charset.IntegrationCharset;
|
||||||
import dan200.computercraft.shared.media.common.DefaultMediaProvider;
|
import dan200.computercraft.shared.media.common.DefaultMediaProvider;
|
||||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||||
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
||||||
@ -76,6 +77,7 @@ import net.minecraftforge.event.RegistryEvent;
|
|||||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||||
@ -83,6 +85,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler;
|
|||||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.registries.IForgeRegistry;
|
import net.minecraftforge.registries.IForgeRegistry;
|
||||||
|
import pl.asie.charset.ModCharset;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -117,6 +120,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
{
|
{
|
||||||
registerTileEntities();
|
registerTileEntities();
|
||||||
registerForgeHandlers();
|
registerForgeHandlers();
|
||||||
|
|
||||||
|
if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user