Browse Source

begin power work, add preliminary MCMP support, restore parts of wire code

tags/0.4.0
Adrian Siekierka 2 years ago
parent
commit
82c01bd393
60 changed files with 1420 additions and 283 deletions
  1. 0
    13
      src/api/java/mcmultipart/capabilities/ICapabilityWrapper.java
  2. 1
    1
      src/main/java/pl/asie/charset/ModCharset.java
  3. 4
    2
      src/main/java/pl/asie/charset/api/lib/IAxisRotatable.java
  4. 44
    0
      src/main/java/pl/asie/charset/api/power/discrete/ActionConsumer.java
  5. 4
    0
      src/main/java/pl/asie/charset/api/power/discrete/ActionGenerator.java
  6. 6
    0
      src/main/java/pl/asie/charset/api/power/discrete/IActionListener.java
  7. 1
    0
      src/main/java/pl/asie/charset/api/wires/IBundledEmitter.java
  8. 1
    0
      src/main/java/pl/asie/charset/api/wires/IBundledReceiver.java
  9. 8
    16
      src/main/java/pl/asie/charset/audio/note/CharsetAudioNoteblock.java
  10. 2
    1
      src/main/java/pl/asie/charset/lib/CharsetLib.java
  11. 35
    0
      src/main/java/pl/asie/charset/lib/annotation/AnnotatedPluginHandler.java
  12. 24
    11
      src/main/java/pl/asie/charset/lib/annotation/AnnotationHandler.java
  13. 2
    1
      src/main/java/pl/asie/charset/lib/audio/manager/AudioStreamManager.java
  14. 28
    28
      src/main/java/pl/asie/charset/lib/capability/Capabilities.java
  15. 15
    5
      src/main/java/pl/asie/charset/lib/capability/CapabilityProviderFactory.java
  16. 8
    12
      src/main/java/pl/asie/charset/lib/capability/audio/AudioReceiverWrapper.java
  17. 9
    13
      src/main/java/pl/asie/charset/lib/capability/inventory/ItemInsertionHandlerWrapper.java
  18. 31
    0
      src/main/java/pl/asie/charset/lib/capability/lib/AxisRotatableWrapper.java
  19. 7
    12
      src/main/java/pl/asie/charset/lib/capability/lib/DebuggableWrapper.java
  20. 1
    1
      src/main/java/pl/asie/charset/lib/capability/lib/DefaultAxisRotatable.java
  21. 0
    54
      src/main/java/pl/asie/charset/lib/capability/pipe/PipeViewWrapper.java
  22. 4
    8
      src/main/java/pl/asie/charset/lib/capability/redstone/BundledEmitterWrapper.java
  23. 5
    9
      src/main/java/pl/asie/charset/lib/capability/redstone/BundledReceiverWrapper.java
  24. 4
    8
      src/main/java/pl/asie/charset/lib/capability/redstone/RedstoneEmitterWrapper.java
  25. 9
    12
      src/main/java/pl/asie/charset/lib/capability/redstone/RedstoneReceiverWrapper.java
  26. 4
    20
      src/main/java/pl/asie/charset/lib/modcompat/jei/JEIPluginCharset.java
  27. 8
    0
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/CharsetMCMPAddon.java
  28. 23
    0
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MCMPAddonCharset.java
  29. 18
    0
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartTile.java
  30. 35
    0
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/OcclusionUtilsMultipart.java
  31. 20
    0
      src/main/java/pl/asie/charset/lib/utils/FunctionalUtils.java
  32. 29
    0
      src/main/java/pl/asie/charset/lib/utils/OcclusionUtils.java
  33. 2
    2
      src/main/java/pl/asie/charset/lib/utils/RotationUtils.java
  34. 2
    1
      src/main/java/pl/asie/charset/lib/utils/UtilProxyCommon.java
  35. 16
    0
      src/main/java/pl/asie/charset/lib/utils/nbt/DefaultNBTSerializers.java
  36. 28
    0
      src/main/java/pl/asie/charset/lib/utils/nbt/NBTSerializer.java
  37. 22
    0
      src/main/java/pl/asie/charset/lib/wires/BlockWire.java
  38. 12
    0
      src/main/java/pl/asie/charset/lib/wires/ItemWire.java
  39. 532
    0
      src/main/java/pl/asie/charset/lib/wires/RendererWire.java
  40. 12
    0
      src/main/java/pl/asie/charset/lib/wires/TileWire.java
  41. 62
    0
      src/main/java/pl/asie/charset/lib/wires/Wire.java
  42. 38
    0
      src/main/java/pl/asie/charset/lib/wires/WireFactory.java
  43. 24
    0
      src/main/java/pl/asie/charset/lib/wires/WireManager.java
  44. 24
    0
      src/main/java/pl/asie/charset/lib/wires/WireUtils.java
  45. 10
    0
      src/main/java/pl/asie/charset/misc/shelf/BlockShelf.java
  46. 41
    0
      src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MCMPAddonMiscShelf.java
  47. 34
    0
      src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MultipartShelf.java
  48. 11
    0
      src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MultipartTileShelf.java
  49. 5
    3
      src/main/java/pl/asie/charset/pipes/CharsetPipes.java
  50. 5
    20
      src/main/java/pl/asie/charset/pipes/PipeUtils.java
  51. 48
    0
      src/main/java/pl/asie/charset/pipes/modcompat/mcmultipart/MCMPAddonPipes.java
  52. 36
    0
      src/main/java/pl/asie/charset/pipes/modcompat/mcmultipart/MultipartPipe.java
  53. 12
    0
      src/main/java/pl/asie/charset/pipes/modcompat/mcmultipart/MultipartTilePipe.java
  54. 13
    1
      src/main/java/pl/asie/charset/pipes/pipe/BlockPipe.java
  55. 15
    21
      src/main/java/pl/asie/charset/pipes/pipe/TilePipe.java
  56. 10
    0
      src/main/java/pl/asie/charset/power/CharsetPower.java
  57. 6
    4
      src/main/java/pl/asie/charset/storage/barrels/TileEntityDayBarrel.java
  58. 1
    1
      src/main/java/pl/asie/charset/transport/carts/CharsetTransportCarts.java
  59. 7
    1
      src/main/java/pl/asie/charset/transport/carts/link/Linkable.java
  60. 2
    2
      src/main/java/pl/asie/charset/transport/carts/link/TrainLinker.java

+ 0
- 13
src/api/java/mcmultipart/capabilities/ICapabilityWrapper.java View File

@@ -1,13 +0,0 @@
package mcmultipart.capabilities;

import java.util.Collection;

import net.minecraftforge.common.capabilities.Capability;

public interface ICapabilityWrapper<T> {

public Capability<T> getCapability();

public T wrapImplementations(Collection<T> implementations);

}

+ 1
- 1
src/main/java/pl/asie/charset/ModCharset.java View File

@@ -58,7 +58,7 @@ public class ModCharset {
public static final String MODID = "charset";
public static final String NAME = "Charset";
public static final String VERSION = "@VERSION@";
public static final String DEP_LIB = "required-after:forge@[13.19.1.2188,);after:mcmultipart;after:jei@[4.0.5.201,)";
public static final String DEP_LIB = "required-after:forge@[13.19.1.2188,);after:jei@[4.0.5.201,);before:betterwithmods;before:mcmultipart";

public static final boolean INDEV = ("@version@".equals(VERSION.toLowerCase()));


+ 4
- 2
src/main/java/pl/asie/charset/api/lib/IAxisRotatable.java View File

@@ -22,15 +22,17 @@ public interface IAxisRotatable {
* @param world The world.
* @param pos The block position.
* @param axis The axis.
* @param simulate Whether the rotation should only be simulated.
* @return Whether the rotation was successful.
*/
boolean rotateAround(World world, BlockPos pos, EnumFacing axis);
boolean rotateAround(World world, BlockPos pos, EnumFacing axis, boolean simulate);
}

/**
* Rotate clockwise around the given axis.
* @param axis The axis.
* @param simulate Whether the rotation should only be simulated.
* @return Whether the rotation was successful.
*/
boolean rotateAround(EnumFacing axis);
boolean rotateAround(EnumFacing axis, boolean simulate);
}

+ 44
- 0
src/main/java/pl/asie/charset/api/power/discrete/ActionConsumer.java View File

@@ -0,0 +1,44 @@
package pl.asie.charset.api.power.discrete;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.INBTSerializable;

public class ActionConsumer implements INBTSerializable<NBTTagCompound> {
protected final World world;
private final IActionListener listener;
private long lastConsumedTime;

public ActionConsumer(World world) {
this.world = world;
this.listener = this instanceof IActionListener ? (IActionListener) this : null;
}

public ActionConsumer(World world, IActionListener listener) {
this.world = world;
this.listener = listener;
}

final void receiveAction() {
lastConsumedTime = world.getTotalWorldTime();
if (listener != null) {
listener.onActionReceived();
}
}

@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setLong("lct", lastConsumedTime);
return compound;
}

@Override
public void deserializeNBT(NBTTagCompound compound) {
if (compound.hasKey("lct")) {
lastConsumedTime = compound.getLong("lct");
} else {
lastConsumedTime = 0;
}
}
}

+ 4
- 0
src/main/java/pl/asie/charset/api/power/discrete/ActionGenerator.java View File

@@ -0,0 +1,4 @@
package pl.asie.charset.api.power.discrete;

public class ActionGenerator {
}

+ 6
- 0
src/main/java/pl/asie/charset/api/power/discrete/IActionListener.java View File

@@ -0,0 +1,6 @@
package pl.asie.charset.api.power.discrete;

@FunctionalInterface
public interface IActionListener {
void onActionReceived();
}

+ 1
- 0
src/main/java/pl/asie/charset/api/wires/IBundledEmitter.java View File

@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
* Implement this class as a capability if you want to
* emit a bundled cable signal.
*/
@Deprecated
public interface IBundledEmitter {
/**
* Get the signal values of a bundled signal emitter.

+ 1
- 0
src/main/java/pl/asie/charset/api/wires/IBundledReceiver.java View File

@@ -20,6 +20,7 @@ package pl.asie.charset.api.wires;
* Implement this class as a capability if you want to
* receive signals from bundled cables.
*/
@Deprecated
public interface IBundledReceiver {
/**
* This function will be called when a connected bundled cable changes.

+ 8
- 16
src/main/java/pl/asie/charset/audio/note/CharsetAudioNoteblock.java View File

@@ -24,20 +24,25 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.tuple.Pair;
import pl.asie.charset.api.audio.AudioPacket;
import pl.asie.charset.api.audio.IAudioSource;
import pl.asie.charset.lib.annotation.CharsetModule;
import pl.asie.charset.lib.audio.types.AudioDataGameSound;
import pl.asie.charset.lib.capability.Capabilities;
import pl.asie.charset.lib.capability.CapabilityProviderFactory;
import pl.asie.charset.lib.capability.audio.DefaultAudioSource;
import pl.asie.charset.lib.network.PacketRegistry;
import pl.asie.charset.lib.utils.FunctionalUtils;

import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Supplier;

@CharsetModule(
name = "audio.noteblock",
description = "Noteblock rework. WIP"
)
public class CharsetAudioNoteblock {
private static final Supplier<CapabilityProviderFactory<IAudioSource>> PROVIDER = FunctionalUtils.lazySupplier(() -> new CapabilityProviderFactory<>(Capabilities.AUDIO_SOURCE));
private static final List<Pair<Predicate<IBlockState>, SoundEvent>> INSTRUMENTS = new ArrayList<>();
private static final SoundEvent DEFAULT_INSTRUMENT;
private static final ResourceLocation NOTE_SOURCE_KEY = new ResourceLocation("charsetaudio:noteSource");
@@ -45,7 +50,6 @@ public class CharsetAudioNoteblock {
@CharsetModule.PacketRegistry
public PacketRegistry packet;


static {
DEFAULT_INSTRUMENT = SoundEvents.BLOCK_NOTE_HARP;

@@ -110,21 +114,9 @@ public class CharsetAudioNoteblock {
}

@SubscribeEvent
public void onAttach(AttachCapabilitiesEvent.TileEntity event) {
if (event.getTileEntity() instanceof TileEntityNote) {
event.addCapability(NOTE_SOURCE_KEY, new ICapabilityProvider() {
private final DefaultAudioSource source = new DefaultAudioSource();

@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
return capability == Capabilities.AUDIO_SOURCE;
}

@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
return capability == Capabilities.AUDIO_SOURCE ? Capabilities.AUDIO_SOURCE.cast(source) : null;
}
});
public void onAttach(AttachCapabilitiesEvent<TileEntity> event) {
if (event.getObject() instanceof TileEntityNote) {
event.addCapability(NOTE_SOURCE_KEY, PROVIDER.get().create(new DefaultAudioSource()));
}
}
}

+ 2
- 1
src/main/java/pl/asie/charset/lib/CharsetLib.java View File

@@ -121,7 +121,7 @@ public class CharsetLib {
// ModCharset.proxy.registerItemModel(WireManager.ITEM, i, "charsetlib:wire");
// }

Capabilities.init();
Capabilities.preInit();
NotifyImplementation.init();

config.save();
@@ -143,6 +143,7 @@ public class CharsetLib {

MinecraftForge.EVENT_BUS.register(this);

Capabilities.init();
ColorUtils.init();
DataSerializersCharset.init();


+ 35
- 0
src/main/java/pl/asie/charset/lib/annotation/AnnotatedPluginHandler.java View File

@@ -0,0 +1,35 @@
package pl.asie.charset.lib.annotation;

import com.google.common.collect.ImmutableSet;

import java.util.Set;

public abstract class AnnotatedPluginHandler<T> {
private final Class annotationClass;
private Set<T> plugins = null;

protected AnnotatedPluginHandler(Class annotationClass) {
this.annotationClass = annotationClass;
}

@SuppressWarnings("unchecked")
public Set<T> getPlugins() {
if (plugins == null) {
ImmutableSet.Builder<T> builder = new ImmutableSet.Builder<>();

for (String s : AnnotationHandler.classNames.get(annotationClass)) {
try {
T plugin = (T) Class.forName(s).newInstance();
builder.add(plugin);
} catch (Exception e) {
e.printStackTrace();
}
}

plugins = builder.build();
AnnotationHandler.classNames.removeAll(annotationClass);
}
return plugins;
}

}

+ 24
- 11
src/main/java/pl/asie/charset/lib/annotation/AnnotationHandler.java View File

@@ -16,6 +16,7 @@ import net.minecraftforge.fml.common.event.FMLEvent;
import org.apache.commons.lang3.tuple.Pair;
import pl.asie.charset.ModCharset;
import pl.asie.charset.lib.modcompat.jei.CharsetJEIPlugin;
import pl.asie.charset.lib.modcompat.mcmultipart.CharsetMCMPAddon;
import pl.asie.charset.lib.network.PacketRegistry;

import java.lang.invoke.MethodHandle;
@@ -32,7 +33,7 @@ import java.util.function.BiConsumer;

public class AnnotationHandler {
public static final AnnotationHandler INSTANCE = new AnnotationHandler();
public static final Set<String> jeiPluginClassNames = new HashSet<>();
public static final Multimap<Class, String> classNames = HashMultimap.create();

private static final Multimap<String, String> dependencies = HashMultimap.create();
private static final Multimap<Class, Pair<String, MethodHandle>> loaderHandles =
@@ -108,6 +109,22 @@ public class AnnotationHandler {
}
}

private void addClassNames(ASMDataTable table, Class annotationClass, String confType) {
for (ASMDataTable.ASMData data : table.getAll(annotationClass.getName())) {
String id = (String) data.getAnnotationInfo().get("value");
Property prop = ModCharset.configModules.get(
"modules.compat",
confType + ":" + id,
true
);
boolean enabled = prop.getBoolean();

if (enabled && loadedModules.containsKey(id)) {
classNames.put(annotationClass, data.getClassName());
}
}
}

@SuppressWarnings("unchecked")
private void readDataTable(ASMDataTable table) {
Set<String> unmetDependencies = new HashSet<>();
@@ -189,10 +206,6 @@ public class AnnotationHandler {
throw new RuntimeException("The following dependencies were not met: " + deps);
}

if (ModCharset.configModules.hasChanged()) {
ModCharset.configModules.save();
}

iterateModules(table, Mod.EventHandler.class.getName(), (data, instance) -> {
String methodName = data.getObjectName().substring(0, data.getObjectName().indexOf('('));
String methodDesc = data.getObjectName().substring(methodName.length());
@@ -253,12 +266,8 @@ public class AnnotationHandler {
}
});

for (ASMDataTable.ASMData data : table.getAll(CharsetJEIPlugin.class.getName())) {
String id = (String) data.getAnnotationInfo().get("value");
if (loadedModules.containsKey(id)) {
jeiPluginClassNames.add(data.getClassName());
}
}
addClassNames(table, CharsetJEIPlugin.class, "jei");
addClassNames(table, CharsetMCMPAddon.class, "mcmultipart");
}

public void passEvent(FMLEvent o) {
@@ -274,6 +283,10 @@ public class AnnotationHandler {

public void preInit(ASMDataTable table) {
readDataTable(table);

if (ModCharset.configModules.hasChanged()) {
ModCharset.configModules.save();
}
}

public void init() {

+ 2
- 1
src/main/java/pl/asie/charset/lib/audio/manager/AudioStreamManager.java View File

@@ -17,9 +17,10 @@
package pl.asie.charset.lib.audio.manager;

import net.minecraftforge.fml.common.SidedProxy;
import pl.asie.charset.ModCharset;

public abstract class AudioStreamManager {
@SidedProxy(clientSide = "pl.asie.charset.lib.audio.manager.AudioStreamManagerClient", serverSide = "pl.asie.charset.lib.audio.manager.AudioStreamManagerServer")
@SidedProxy(clientSide = "pl.asie.charset.lib.audio.manager.AudioStreamManagerClient", serverSide = "pl.asie.charset.lib.audio.manager.AudioStreamManagerServer", modId = ModCharset.MODID)
public static AudioStreamManager INSTANCE;

public abstract void put(int id, IAudioStream stream);

+ 28
- 28
src/main/java/pl/asie/charset/lib/capability/Capabilities.java View File

@@ -16,6 +16,7 @@

package pl.asie.charset.lib.capability;

import mcmultipart.api.capability.MCMPCapabilityHelper;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
@@ -34,21 +35,18 @@ import pl.asie.charset.api.wires.IBundledEmitter;
import pl.asie.charset.api.wires.IBundledReceiver;
import pl.asie.charset.api.wires.IRedstoneEmitter;
import pl.asie.charset.api.wires.IRedstoneReceiver;
import pl.asie.charset.lib.capability.audio.AudioReceiverWrapper;
import pl.asie.charset.lib.capability.audio.DefaultAudioReceiver;
import pl.asie.charset.lib.capability.audio.DefaultAudioSource;
import pl.asie.charset.lib.capability.inventory.DefaultItemInsertionHandler;
import pl.asie.charset.lib.capability.lib.DefaultAxisRotatable;
import pl.asie.charset.lib.capability.lib.DefaultDebuggable;
import pl.asie.charset.lib.capability.lib.DefaultMovable;
import pl.asie.charset.lib.capability.inventory.ItemInsertionHandlerWrapper;
import pl.asie.charset.lib.capability.lib.*;
import pl.asie.charset.lib.capability.pipe.DefaultPipeView;
import pl.asie.charset.lib.capability.providers.CapabilityWrapperFluidStacks;
import pl.asie.charset.lib.capability.providers.CapabilityWrapperInsertionToItemHandler;
import pl.asie.charset.lib.capability.providers.CapabilityWrapperInventory;
import pl.asie.charset.lib.capability.redstone.DefaultBundledEmitter;
import pl.asie.charset.lib.capability.redstone.DefaultBundledEmitterStorage;
import pl.asie.charset.lib.capability.redstone.DefaultRedstoneEmitter;
import pl.asie.charset.lib.capability.redstone.DefaultRedstoneEmitterStorage;
import pl.asie.charset.lib.capability.redstone.DummyRedstoneReceiver;
import pl.asie.charset.lib.capability.redstone.*;
import pl.asie.charset.lib.wires.Wire;

public class Capabilities {
@CapabilityInject(IAudioSource.class)
@@ -77,38 +75,40 @@ public class Capabilities {
@CapabilityInject(IRedstoneReceiver.class)
public static Capability<IRedstoneReceiver> REDSTONE_RECEIVER;

public static void init() {
CapabilityManager.INSTANCE.register(IAudioSource.class, new NullCapabilityStorage<IAudioSource>(), DefaultAudioSource::new);
CapabilityManager.INSTANCE.register(IAudioReceiver.class, new NullCapabilityStorage<IAudioReceiver>(), DefaultAudioReceiver::new);
public static void preInit() {
CapabilityManager.INSTANCE.register(IAudioSource.class, new NullCapabilityStorage<>(), DefaultAudioSource::new);
CapabilityManager.INSTANCE.register(IAudioReceiver.class, new NullCapabilityStorage<>(), DefaultAudioReceiver::new);

CapabilityManager.INSTANCE.register(IAxisRotatable.class, new NullCapabilityStorage<IAxisRotatable>(), DefaultAxisRotatable::new);
CapabilityManager.INSTANCE.register(IDebuggable.class, new NullCapabilityStorage<IDebuggable>(), DefaultDebuggable::new);
CapabilityManager.INSTANCE.register(IMovable.class, new NullCapabilityStorage<IMovable>(), DefaultMovable::new);
CapabilityManager.INSTANCE.register(IAxisRotatable.class, new NullCapabilityStorage<>(), DefaultAxisRotatable::new);
CapabilityManager.INSTANCE.register(IDebuggable.class, new NullCapabilityStorage<>(), DefaultDebuggable::new);
CapabilityManager.INSTANCE.register(IMovable.class, new NullCapabilityStorage<>(), DefaultMovable::new);

CapabilityManager.INSTANCE.register(IItemInsertionHandler.class, new NullCapabilityStorage<IItemInsertionHandler>(), DefaultItemInsertionHandler::new);
CapabilityManager.INSTANCE.register(IPipeView.class, new NullCapabilityStorage<IPipeView>(), DefaultPipeView::new);
CapabilityManager.INSTANCE.register(IItemInsertionHandler.class, new NullCapabilityStorage<>(), DefaultItemInsertionHandler::new);
CapabilityManager.INSTANCE.register(IPipeView.class, new NullCapabilityStorage<>(), DefaultPipeView::new);

CapabilityManager.INSTANCE.register(IBundledEmitter.class, new DefaultBundledEmitterStorage(), DefaultBundledEmitter::new);
CapabilityManager.INSTANCE.register(IRedstoneEmitter.class, new DefaultRedstoneEmitterStorage(), DefaultRedstoneEmitter::new);
CapabilityManager.INSTANCE.register(IBundledReceiver.class, new NullCapabilityStorage<IBundledReceiver>(), DummyRedstoneReceiver::new);
CapabilityManager.INSTANCE.register(IRedstoneReceiver.class, new NullCapabilityStorage<IRedstoneReceiver>(), DummyRedstoneReceiver::new);
CapabilityManager.INSTANCE.register(IBundledReceiver.class, new NullCapabilityStorage<>(), DummyRedstoneReceiver::new);
CapabilityManager.INSTANCE.register(IRedstoneReceiver.class, new NullCapabilityStorage<>(), DummyRedstoneReceiver::new);
}

public static void init() {
if (Loader.isModLoaded("mcmultipart")) {
initMultiplePants();
}
}
}

@Optional.Method(modid = "mcmultipart")
private static void initMultiplePants() {
// TODO 1.11
// CapabilityWrapperRegistry.registerCapabilityWrapper(new AudioReceiverWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new BundledEmitterWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new RedstoneEmitterWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new BundledReceiverWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new RedstoneReceiverWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new DebuggableWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new ItemInsertionHandlerWrapper());
// CapabilityWrapperRegistry.registerCapabilityWrapper(new PipeViewWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(AUDIO_RECEIVER, new AudioReceiverWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(BUNDLED_EMITTER, new BundledEmitterWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(REDSTONE_EMITTER, new RedstoneEmitterWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(BUNDLED_RECEIVER, new BundledReceiverWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(REDSTONE_RECEIVER, new RedstoneReceiverWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(AXIS_ROTATABLE, new AxisRotatableWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(DEBUGGABLE, new DebuggableWrapper());
MCMPCapabilityHelper.registerCapabilityJoiner(ITEM_INSERTION_HANDLER, new ItemInsertionHandlerWrapper());
}

public static void registerVanillaWrappers() {

+ 15
- 5
src/main/java/pl/asie/charset/lib/capability/CapabilityProviderFactory.java View File

@@ -13,8 +13,8 @@ public class CapabilityProviderFactory<T> {
private final Capability<T> capability;
private final Capability.IStorage<T> storage;

private class Provider implements ICapabilitySerializable<NBTBase> {
private final T object;
private class Provider implements ICapabilityProvider {
protected final T object;

private Provider(T object) {
this.object = object;
@@ -30,6 +30,12 @@ public class CapabilityProviderFactory<T> {
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return capability == CapabilityProviderFactory.this.capability ? CapabilityProviderFactory.this.capability.cast(object) : null;
}
}

private class ProviderSerializable extends Provider implements ICapabilitySerializable<NBTBase> {
private ProviderSerializable(T object) {
super(object);
}

@Override
public NBTBase serializeNBT() {
@@ -38,17 +44,21 @@ public class CapabilityProviderFactory<T> {

@Override
public void deserializeNBT(NBTBase nbt) {
storage.readNBT(capability, object, null, nbt);
if (storage != null) storage.readNBT(capability, object, null, nbt);
}
}

public CapabilityProviderFactory(Capability<T> capability, Capability.IStorage<T> storage) {
public CapabilityProviderFactory(@Nonnull Capability<T> capability) {
this(capability, null);
}

public CapabilityProviderFactory(@Nonnull Capability<T> capability, @Nullable Capability.IStorage<T> storage) {
this.capability = capability;
this.storage = storage;
}

public ICapabilityProvider create(T object) {
return new Provider(object);
return storage != null ? new ProviderSerializable(object) : new Provider(object);
}

public Capability.IStorage<T> getStorage() {

+ 8
- 12
src/main/java/pl/asie/charset/lib/capability/audio/AudioReceiverWrapper.java View File

@@ -16,15 +16,21 @@

package pl.asie.charset.lib.capability.audio;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.audio.AudioPacket;
import pl.asie.charset.api.audio.IAudioReceiver;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class AudioReceiverWrapper implements Function<List<IAudioReceiver>, IAudioReceiver> {
@Override
public IAudioReceiver apply(List<IAudioReceiver> iAudioReceivers) {
return new WrappedReceiver(iAudioReceivers);
}

public class AudioReceiverWrapper implements ICapabilityWrapper<IAudioReceiver> {
private class WrappedReceiver implements IAudioReceiver {
private final Collection<IAudioReceiver> receivers;

@@ -41,14 +47,4 @@ public class AudioReceiverWrapper implements ICapabilityWrapper<IAudioReceiver>
return received;
}
}

@Override
public Capability<IAudioReceiver> getCapability() {
return Capabilities.AUDIO_RECEIVER;
}

@Override
public IAudioReceiver wrapImplementations(Collection<IAudioReceiver> implementations) {
return new WrappedReceiver(implementations);
}
}

+ 9
- 13
src/main/java/pl/asie/charset/lib/capability/inventory/ItemInsertionHandlerWrapper.java View File

@@ -16,15 +16,21 @@

package pl.asie.charset.lib.capability.inventory;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.lib.IItemInsertionHandler;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class ItemInsertionHandlerWrapper implements Function<List<IItemInsertionHandler>, IItemInsertionHandler> {
@Override
public IItemInsertionHandler apply(List<IItemInsertionHandler> iItemInsertionHandlers) {
return new WrappedInserter(iItemInsertionHandlers);
}

public class ItemInsertionHandlerWrapper implements ICapabilityWrapper<IItemInsertionHandler> {
private class WrappedInserter implements IItemInsertionHandler {
private final Collection<IItemInsertionHandler> receivers;

@@ -36,21 +42,11 @@ public class ItemInsertionHandlerWrapper implements ICapabilityWrapper<IItemInse
public ItemStack insertItem(ItemStack stack, boolean simulate) {
ItemStack toInsert = stack;
for (IItemInsertionHandler insertionHandler : receivers) {
toInsert = insertionHandler.insertItem(toInsert, simulate);
if (toInsert.isEmpty())
break;
toInsert = insertionHandler.insertItem(toInsert, simulate);
}
return toInsert;
}
}

@Override
public Capability<IItemInsertionHandler> getCapability() {
return Capabilities.ITEM_INSERTION_HANDLER;
}

@Override
public IItemInsertionHandler wrapImplementations(Collection<IItemInsertionHandler> implementations) {
return new WrappedInserter(implementations);
}
}

+ 31
- 0
src/main/java/pl/asie/charset/lib/capability/lib/AxisRotatableWrapper.java View File

@@ -0,0 +1,31 @@
package pl.asie.charset.lib.capability.lib;

import net.minecraft.util.EnumFacing;
import pl.asie.charset.api.lib.IAxisRotatable;

import java.util.List;
import java.util.function.Function;

public class AxisRotatableWrapper implements Function<List<IAxisRotatable>, IAxisRotatable> {
@Override
public IAxisRotatable apply(List<IAxisRotatable> iAxisRotatableList) {
return new IAxisRotatable() {
@Override
public boolean rotateAround(EnumFacing axis, boolean simulate) {
for (IAxisRotatable rotatable : iAxisRotatableList) {
if (!rotatable.rotateAround(axis, true)) {
return false;
}
}

if (!simulate) {
for (IAxisRotatable rotatable : iAxisRotatableList) {
rotatable.rotateAround(axis, false);
}
}

return true;
}
};
}
}

+ 7
- 12
src/main/java/pl/asie/charset/lib/capability/lib/DebuggableWrapper.java View File

@@ -1,6 +1,5 @@
package pl.asie.charset.lib.capability.lib;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
import pl.asie.charset.api.lib.IDebuggable;
@@ -8,8 +7,14 @@ import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class DebuggableWrapper implements Function<List<IDebuggable>, IDebuggable> {
@Override
public IDebuggable apply(List<IDebuggable> iDebuggables) {
return new Wrapped(iDebuggables);
}

public class DebuggableWrapper implements ICapabilityWrapper<IDebuggable> {
private class Wrapped implements IDebuggable {
private final Collection<IDebuggable> receivers;

@@ -23,14 +28,4 @@ public class DebuggableWrapper implements ICapabilityWrapper<IDebuggable> {
debug.addDebugInformation(stringList, side);
}
}

@Override
public Capability<IDebuggable> getCapability() {
return Capabilities.DEBUGGABLE;
}

@Override
public IDebuggable wrapImplementations(Collection<IDebuggable> implementations) {
return new Wrapped(implementations);
}
}

+ 1
- 1
src/main/java/pl/asie/charset/lib/capability/lib/DefaultAxisRotatable.java View File

@@ -5,7 +5,7 @@ import pl.asie.charset.api.lib.IAxisRotatable;

public class DefaultAxisRotatable implements IAxisRotatable {
@Override
public boolean rotateAround(EnumFacing axis) {
public boolean rotateAround(EnumFacing axis, boolean simulate) {
return false;
}
}

+ 0
- 54
src/main/java/pl/asie/charset/lib/capability/pipe/PipeViewWrapper.java View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) 2015-2016 Adrian Siekierka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.asie.charset.lib.capability.pipe;

import com.google.common.collect.ImmutableList;
import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.pipes.IPipeView;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;

public class PipeViewWrapper implements ICapabilityWrapper<IPipeView> {
private class Wrapped implements IPipeView {
private final Collection<IPipeView> receivers;

Wrapped(Collection<IPipeView> receivers) {
this.receivers = receivers;
}

@Override
public Collection<ItemStack> getTravellingStacks() {
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for (IPipeView view : receivers)
builder.addAll(view.getTravellingStacks());
return builder.build();
}
}

@Override
public Capability<IPipeView> getCapability() {
return Capabilities.PIPE_VIEW;
}

@Override
public IPipeView wrapImplementations(Collection<IPipeView> implementations) {
return new Wrapped(implementations);
}
}

+ 4
- 8
src/main/java/pl/asie/charset/lib/capability/redstone/BundledEmitterWrapper.java View File

@@ -16,21 +16,17 @@

package pl.asie.charset.lib.capability.redstone;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.wires.IBundledEmitter;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class BundledEmitterWrapper implements ICapabilityWrapper<IBundledEmitter> {
public class BundledEmitterWrapper implements Function<List<IBundledEmitter>, IBundledEmitter> {
@Override
public Capability<IBundledEmitter> getCapability() {
return Capabilities.BUNDLED_EMITTER;
}

@Override
public IBundledEmitter wrapImplementations(Collection<IBundledEmitter> collection) {
public IBundledEmitter apply(List<IBundledEmitter> collection) {
byte[] data = new byte[16];

for (IBundledEmitter emitter : collection) {

+ 5
- 9
src/main/java/pl/asie/charset/lib/capability/redstone/BundledReceiverWrapper.java View File

@@ -16,14 +16,15 @@

package pl.asie.charset.lib.capability.redstone;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.wires.IBundledReceiver;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class BundledReceiverWrapper implements ICapabilityWrapper<IBundledReceiver> {
public class BundledReceiverWrapper implements Function<List<IBundledReceiver>, IBundledReceiver> {
private class WrappedReceiver implements IBundledReceiver {
private final Collection<IBundledReceiver> receiverSet;

@@ -40,12 +41,7 @@ public class BundledReceiverWrapper implements ICapabilityWrapper<IBundledReceiv
}

@Override
public Capability<IBundledReceiver> getCapability() {
return Capabilities.BUNDLED_RECEIVER;
}

@Override
public IBundledReceiver wrapImplementations(Collection<IBundledReceiver> collection) {
return new WrappedReceiver(collection);
public IBundledReceiver apply(List<IBundledReceiver> iBundledReceivers) {
return new WrappedReceiver(iBundledReceivers);
}
}

+ 4
- 8
src/main/java/pl/asie/charset/lib/capability/redstone/RedstoneEmitterWrapper.java View File

@@ -16,21 +16,17 @@

package pl.asie.charset.lib.capability.redstone;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.wires.IRedstoneEmitter;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class RedstoneEmitterWrapper implements ICapabilityWrapper<IRedstoneEmitter> {
public class RedstoneEmitterWrapper implements Function<List<IRedstoneEmitter>, IRedstoneEmitter> {
@Override
public Capability<IRedstoneEmitter> getCapability() {
return Capabilities.REDSTONE_EMITTER;
}

@Override
public IRedstoneEmitter wrapImplementations(Collection<IRedstoneEmitter> collection) {
public IRedstoneEmitter apply(List<IRedstoneEmitter> collection) {
int data = 0;

for (IRedstoneEmitter emitter : collection) {

+ 9
- 12
src/main/java/pl/asie/charset/lib/capability/redstone/RedstoneReceiverWrapper.java View File

@@ -16,14 +16,21 @@

package pl.asie.charset.lib.capability.redstone;

import mcmultipart.capabilities.ICapabilityWrapper;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.api.wires.IBundledReceiver;
import pl.asie.charset.api.wires.IRedstoneReceiver;
import pl.asie.charset.lib.capability.Capabilities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

public class RedstoneReceiverWrapper implements Function<List<IRedstoneReceiver>, IRedstoneReceiver> {
@Override
public IRedstoneReceiver apply(List<IRedstoneReceiver> iRedstoneReceivers) {
return new WrappedReceiver(iRedstoneReceivers);
}

public class RedstoneReceiverWrapper implements ICapabilityWrapper<IRedstoneReceiver> {
private class WrappedReceiver implements IRedstoneReceiver {
private final Collection<IRedstoneReceiver> receiverSet;

@@ -38,14 +45,4 @@ public class RedstoneReceiverWrapper implements ICapabilityWrapper<IRedstoneRece
}
}
}

@Override
public Capability<IRedstoneReceiver> getCapability() {
return Capabilities.REDSTONE_RECEIVER;
}

@Override
public IRedstoneReceiver wrapImplementations(Collection<IRedstoneReceiver> collection) {
return new WrappedReceiver(collection);
}
}

+ 4
- 20
src/main/java/pl/asie/charset/lib/modcompat/jei/JEIPluginCharset.java View File

@@ -12,6 +12,7 @@ import mezz.jei.api.recipe.IStackHelper;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import pl.asie.charset.lib.annotation.AnnotatedPluginHandler;
import pl.asie.charset.lib.annotation.AnnotationHandler;

import javax.annotation.Nonnull;
@@ -19,30 +20,13 @@ import javax.annotation.Nullable;
import java.util.Set;

@JEIPlugin
public class JEIPluginCharset implements IModPlugin {
public class JEIPluginCharset extends AnnotatedPluginHandler<IModPlugin> implements IModPlugin {
public static IStackHelper STACKS;
public static IRecipeTransferHandlerHelper RECIPE_TRANSFER_HANDLERS;
public static IGuiHelper GUIS;

private Set<IModPlugin> plugins = null;

public Set<IModPlugin> getPlugins() {
if (plugins == null) {
ImmutableSet.Builder<IModPlugin> builder = new ImmutableSet.Builder<>();

for (String s : AnnotationHandler.jeiPluginClassNames) {
try {
IModPlugin plugin = (IModPlugin) Class.forName(s).newInstance();
builder.add(plugin);
} catch (Exception e) {
e.printStackTrace();
}
}

plugins = builder.build();
AnnotationHandler.jeiPluginClassNames.clear();
}
return plugins;
public JEIPluginCharset() {
super(CharsetJEIPlugin.class);
}

@Override

+ 8
- 0
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/CharsetMCMPAddon.java View File

@@ -0,0 +1,8 @@
package pl.asie.charset.lib.modcompat.mcmultipart;

/**
* Charset's JEI plugin marker, controlled by the belonging module's ID.
*/
public @interface CharsetMCMPAddon {
String value();
}

+ 23
- 0
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MCMPAddonCharset.java View File

@@ -0,0 +1,23 @@
package pl.asie.charset.lib.modcompat.mcmultipart;

import mcmultipart.api.addon.IMCMPAddon;
import mcmultipart.api.addon.MCMPAddon;
import mcmultipart.api.multipart.IMultipartRegistry;
import pl.asie.charset.lib.annotation.AnnotatedPluginHandler;
import pl.asie.charset.lib.utils.OcclusionUtils;

@MCMPAddon
public class MCMPAddonCharset extends AnnotatedPluginHandler<IMCMPAddon> implements IMCMPAddon {
public MCMPAddonCharset() {
super(CharsetMCMPAddon.class);
}

@Override
public void registerParts(IMultipartRegistry registry) {
OcclusionUtils.INSTANCE = new OcclusionUtilsMultipart();

for (IMCMPAddon addon : getPlugins()) {
addon.registerParts(registry);
}
}
}

+ 18
- 0
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartTile.java View File

@@ -0,0 +1,18 @@
package pl.asie.charset.lib.modcompat.mcmultipart;

import mcmultipart.api.multipart.IMultipartTile;
import net.minecraft.tileentity.TileEntity;
import pl.asie.charset.pipes.pipe.TilePipe;

public class MultipartTile<T extends TileEntity> implements IMultipartTile {
protected final T owner;

public MultipartTile(T owner) {
this.owner = owner;
}

@Override
public TileEntity getTileEntity() {
return owner;
}
}

+ 35
- 0
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/OcclusionUtilsMultipart.java View File

@@ -0,0 +1,35 @@
package pl.asie.charset.lib.modcompat.mcmultipart;

import mcmultipart.api.container.IMultipartContainer;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.MultipartHelper;
import mcmultipart.api.multipart.OcclusionHelper;
import mcmultipart.api.world.IMultipartBlockAccess;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import pl.asie.charset.lib.utils.OcclusionUtils;

import java.util.*;

public class OcclusionUtilsMultipart extends OcclusionUtils {
public OcclusionUtilsMultipart() {
}

@Override
public boolean intersects(Collection<AxisAlignedBB> boxes1, IBlockAccess world, BlockPos pos) {
if (world instanceof IMultipartBlockAccess) {
IPartInfo info = ((IMultipartBlockAccess) world).getPartInfo();
for (IPartInfo info2 : info.getContainer().getParts().values()) {
if (info2 != info && OcclusionHelper.testPartIntersection(info, info2)) {
return true;
}
}

return false;
} else {
return super.intersects(boxes1, world, pos);
}
}
}

+ 20
- 0
src/main/java/pl/asie/charset/lib/utils/FunctionalUtils.java View File

@@ -0,0 +1,20 @@
package pl.asie.charset.lib.utils;

import java.util.function.Supplier;

public final class FunctionalUtils {
private FunctionalUtils() {

}

public static <T> Supplier<T> lazySupplier(Supplier<T> creator) {
return new Supplier<T>() {
private T instance;

@Override
public T get() {
return instance == null ? (instance = creator.get()) : instance;
}
};
}
}

+ 29
- 0
src/main/java/pl/asie/charset/lib/utils/OcclusionUtils.java View File

@@ -0,0 +1,29 @@
package pl.asie.charset.lib.utils;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

import java.util.Collection;
import java.util.Collections;

public class OcclusionUtils {
public static OcclusionUtils INSTANCE = new OcclusionUtils();

protected OcclusionUtils() {

}

public boolean intersects(Collection<AxisAlignedBB> boxes1, Collection<AxisAlignedBB> boxes2) {
return boxes1.stream().anyMatch(b1 -> boxes2.stream().anyMatch(b1::intersectsWith));
}

public boolean intersects(Collection<AxisAlignedBB> boxes1, AxisAlignedBB box2) {
return boxes1.stream().anyMatch(box2::intersectsWith);
}

public boolean intersects(Collection<AxisAlignedBB> boxes1, IBlockAccess world, BlockPos pos) {
return intersects(boxes1, world.getBlockState(pos).getBoundingBox(world, pos));
}
}

+ 2
- 2
src/main/java/pl/asie/charset/lib/utils/RotationUtils.java View File

@@ -82,7 +82,7 @@ public final class RotationUtils {
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof IAxisRotatable.IAxisRotatableBlock) {
for (int i = 0; i < count; i++)
if (!((IAxisRotatable.IAxisRotatableBlock) state.getBlock()).rotateAround(world, pos, axis))
if (!((IAxisRotatable.IAxisRotatableBlock) state.getBlock()).rotateAround(world, pos, axis, false))
return false;

return true;
@@ -93,7 +93,7 @@ public final class RotationUtils {
IAxisRotatable rotatable = CapabilityHelper.get(Capabilities.AXIS_ROTATABLE, tile, axis);
if (rotatable != null) {
for (int i = 0; i < count; i++)
if (!rotatable.rotateAround(axis))
if (!rotatable.rotateAround(axis, false))
return false;

return true;

+ 2
- 1
src/main/java/pl/asie/charset/lib/utils/UtilProxyCommon.java View File

@@ -28,9 +28,10 @@ import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.SidedProxy;
import pl.asie.charset.ModCharset;

class UtilProxyCommon implements IThreadListener {
@SidedProxy(clientSide = "pl.asie.charset.lib.utils.UtilProxyClient", serverSide = "pl.asie.charset.lib.utils.UtilProxyCommon")
@SidedProxy(clientSide = "pl.asie.charset.lib.utils.UtilProxyClient", serverSide = "pl.asie.charset.lib.utils.UtilProxyCommon", modId = ModCharset.MODID)
public static UtilProxyCommon proxy;

// TODO 1.11

+ 16
- 0
src/main/java/pl/asie/charset/lib/utils/nbt/DefaultNBTSerializers.java View File

@@ -0,0 +1,16 @@
package pl.asie.charset.lib.utils.nbt;

import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagShort;
import net.minecraftforge.common.util.Constants;

public final class DefaultNBTSerializers {
private DefaultNBTSerializers() {

}

public static void init() {
NBTSerializer.INSTANCE.register(Byte.class, Constants.NBT.TAG_BYTE, NBTTagByte::new, (tag) -> ((NBTTagByte) tag).getByte());
NBTSerializer.INSTANCE.register(Short.class, Constants.NBT.TAG_SHORT, NBTTagShort::new, (tag) -> ((NBTTagShort) tag).getShort());
}
}

+ 28
- 0
src/main/java/pl/asie/charset/lib/utils/nbt/NBTSerializer.java View File

@@ -0,0 +1,28 @@
package pl.asie.charset.lib.utils.nbt;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;

import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;

public final class NBTSerializer {
public static final NBTSerializer INSTANCE = new NBTSerializer();

private final Map<Class, Class> shortcuts = new IdentityHashMap<>();
private final Map<Class, Function<Object, ? extends NBTBase>> serializers = new IdentityHashMap<>();
private final Map<Class, Function<? extends NBTBase, Object>> deserializers = new IdentityHashMap<>();
private final Map<Class, Integer> nbtTypes = new IdentityHashMap<>();

private NBTSerializer() {

}

@SuppressWarnings("unchecked")
public <T> void register(Class<T> tClass, int tagType, Function<T, ? extends NBTBase> serializer, Function<? extends NBTBase, T> deserializer) {
serializers.put(tClass, (Function<Object, ? extends NBTBase>) serializer);
deserializers.put(tClass, (Function<? extends NBTBase, Object>) deserializer);
}
}

+ 22
- 0
src/main/java/pl/asie/charset/lib/wires/BlockWire.java View File

@@ -0,0 +1,22 @@
package pl.asie.charset.lib.wires;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import javax.annotation.Nullable;

public class BlockWire extends Block implements ITileEntityProvider {
public BlockWire() {
super(Material.CIRCUITS);
}

@Nullable
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileWire();
}
}

+ 12
- 0
src/main/java/pl/asie/charset/lib/wires/ItemWire.java View File

@@ -0,0 +1,12 @@
package pl.asie.charset.lib.wires;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;

public class ItemWire extends Item {
public Wire fromStack(ItemStack stack, EnumFacing down) {
// TODO
return null;
}
}

+ 532
- 0
src/main/java/pl/asie/charset/lib/wires/RendererWire.java View File

@@ -0,0 +1,532 @@
/*
* Copyright (c) 2015-2016 Adrian Siekierka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.asie.charset.lib.wires;

import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelRotation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.util.vector.Vector3f;
import pl.asie.charset.api.wires.WireFace;
import pl.asie.charset.lib.render.model.ModelFactory;
import pl.asie.charset.lib.render.model.SimpleBakedModel;
import pl.asie.charset.lib.render.sprite.SpritesheetFactory;
import pl.asie.charset.lib.utils.RenderUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RendererWire extends ModelFactory<Wire> {
public static class WireSheet {
TextureAtlasSprite[] top;
TextureAtlasSprite side, edge, particle;
int width, height;
}

private final ModelRotation[] ROTATIONS = new ModelRotation[]{
ModelRotation.X0_Y0,
ModelRotation.X180_Y0,
ModelRotation.X270_Y0,
ModelRotation.X270_Y180,
ModelRotation.X270_Y270,
ModelRotation.X270_Y90
};

private final TIntObjectMap<Wire> stackMap = new TIntObjectHashMap<>();
private final Map<WireFactory, WireSheet> sheetMap = new HashMap<>();

public RendererWire() {
super(Wire.PROPERTY, new ResourceLocation("charset:blocks/wire_normal_particle"));
addDefaultBlockTransforms();
}

public WireSheet getSheet(WireFactory type) {
return sheetMap.get(type);
}

public void registerSheet(TextureMap map, WireFactory type) {
ResourceLocation location = type.getTexturePrefix();
String domain = location.getResourceDomain();
String path = location.getResourcePath();
WireSheet sheet = new WireSheet();

sheet.top = SpritesheetFactory.register(map, new ResourceLocation(domain, path + "_top"), 4, 4);
sheet.particle = map.registerSprite(new ResourceLocation(domain, path + "_particle"));
sheet.edge = map.registerSprite(new ResourceLocation(domain, path + "_edge"));
sheet.side = map.registerSprite(new ResourceLocation(domain, path + "_side"));

sheet.width = (int) (type.getWidth() * 16);
sheet.height = (int) (type.getHeight() * 16);

sheetMap.put(type, sheet);
}

private boolean wc(Wire wire, EnumFacing facing) {
return wire.connects(facing);
}

private boolean isCenterEdge(Wire wire, WireFace side) {
// TODO
//return wire.getWireType(side) != wire.getWireType(WireFace.CENTER);
return false;
}

private float getCL(Wire wire, WireFace side) {
// TODO
//float h = wire != null && wire.hasWire(side) ? wire.getWireKind(side).height() : 0;
float h = 0;

if (wire != null && isCenterEdge(wire, side)) {
h = 0;
}

if (!wc(wire, side.facing) && wire.getFactory() != null) {
h = 8.0f - (sheetMap.get(wire.getFactory()).width / 2); // TODO: Replace with WireFactory call?
}

return side.facing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE ? 16.0f - h : h;
}

public void addWireFreestanding(Wire wire, WireSheet sheet, int renderColor, List<BakedQuad> quads) {
float min = 8.0f - (sheet.width / 2);
float max = 8.0f + (sheet.width / 2);
Vector3f minX = new Vector3f(min, getCL(wire, WireFace.DOWN), getCL(wire, WireFace.NORTH));
Vector3f maxX = new Vector3f(min, getCL(wire, WireFace.UP), getCL(wire, WireFace.SOUTH));
Vector3f minY = new Vector3f(getCL(wire, WireFace.WEST), min, getCL(wire, WireFace.NORTH));
Vector3f maxY = new Vector3f(getCL(wire, WireFace.EAST), min, getCL(wire, WireFace.SOUTH));
Vector3f minZ = new Vector3f(getCL(wire, WireFace.WEST), getCL(wire, WireFace.DOWN), min);
Vector3f maxZ = new Vector3f(getCL(wire, WireFace.EAST), getCL(wire, WireFace.UP), min);

int cmcX = (wc(wire, EnumFacing.UP) ? 8 : 0) | (wc(wire, EnumFacing.DOWN) ? 4 : 0) | (wc(wire, EnumFacing.NORTH) ? 2 : 0) | (wc(wire, EnumFacing.SOUTH) ? 1 : 0);
int cmcY = (wc(wire, EnumFacing.NORTH) ? 4 : 0) | (wc(wire, EnumFacing.SOUTH) ? 8 : 0) | (wc(wire, EnumFacing.WEST) ? 2 : 0) | (wc(wire, EnumFacing.EAST) ? 1 : 0);
int cmcZ = (wc(wire, EnumFacing.UP) ? 8 : 0) | (wc(wire, EnumFacing.DOWN) ? 4 : 0) | (wc(wire, EnumFacing.WEST) ? 1 : 0) | (wc(wire, EnumFacing.EAST) ? 2 : 0);

for (int i = 0; i < 2; i++) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
minX, maxX, renderColor,
sheet.top[cmcX], i == 0 ? EnumFacing.WEST : EnumFacing.EAST,
ModelRotation.X0_Y0, true
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
minY, maxY, renderColor,
sheet.top[cmcY], i == 0 ? EnumFacing.DOWN : EnumFacing.UP,
ModelRotation.X0_Y0, true
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
minZ, maxZ, renderColor,
sheet.top[cmcZ], i == 0 ? EnumFacing.NORTH : EnumFacing.SOUTH,
ModelRotation.X0_Y0, true
)
);

if (i == 0) {
// set to max
minX.setX(max);
maxX.setX(max);
minY.setY(max);
maxY.setY(max);
minZ.setZ(max);
maxZ.setZ(max);

// swap
cmcY = (cmcY & 0x3) | ((cmcY & 0x8) >> 1) | ((cmcY & 0x4) << 1);
cmcZ = (cmcZ & 0xC) | ((cmcZ & 0x2) >> 1) | ((cmcZ & 0x1) << 1);
cmcX = (cmcX & 0xC) | ((cmcX & 0x2) >> 1) | ((cmcX & 0x1) << 1);
}
}

for (EnumFacing f : EnumFacing.VALUES) {
if (wc(wire, f)) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, 0.0F, min), new Vector3f(max, 0.0f, max),
renderColor,
f.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE ? new float[]{max, min, min, max} : new float[]{min, min, max, max},
sheet.edge, EnumFacing.DOWN, ROTATIONS[f.ordinal()], true
)
);
}
}
}

public void addCorner(Wire wire, WireSheet sheet, EnumFacing dir, int renderColor, List<BakedQuad> quads) {
int width = sheet.width;
int height = sheet.height;

ModelRotation rot = ROTATIONS[wire.location.ordinal()];
float min = 8.0f - (width / 2);
float max = 8.0f + (width / 2);

// Edge faces

float[] edgeUV = new float[]{min, 0, max, height};
float[] edgeUVFlipped = new float[]{max, 0, min, height};

if (dir == EnumFacing.NORTH) {
float[] topUV = new float[]{min, 16 - height, max, 16};

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, 0, -height), new Vector3f(max, height, -height),
renderColor, edgeUVFlipped,
sheet.top[15], EnumFacing.NORTH, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, height, -height), new Vector3f(max, height, 0),
renderColor, topUV,
sheet.top[15], EnumFacing.UP, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, 0, -height), new Vector3f(min, height, 0),
renderColor, edgeUV,
sheet.edge, EnumFacing.WEST, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(max, 0, -height), new Vector3f(max, height, 0),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.EAST, rot, false
)
);
} else if (dir == EnumFacing.SOUTH) {
float[] topUV = new float[]{min, 0, max, height};

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, 0, 16 + height), new Vector3f(max, height, 16 + height),
renderColor, edgeUVFlipped,
sheet.top[15], EnumFacing.SOUTH, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, height, 16), new Vector3f(max, height, 16 + height),
renderColor, topUV,
sheet.top[15], EnumFacing.UP, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, 0, 16), new Vector3f(min, height, 16 + height),
renderColor, edgeUV,
sheet.edge, EnumFacing.WEST, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(max, 0, 16), new Vector3f(max, height, 16 + height),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.EAST, rot, false
)
);
} else if (dir == EnumFacing.WEST) {
float[] topUV = new float[]{16 - height, min, 16, max};

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(-height, height, min), new Vector3f(0, height, max),
renderColor, topUV,
sheet.top[15], EnumFacing.UP, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(-height, 0, min), new Vector3f(-height, height, max),
renderColor, edgeUV,
sheet.top[15], EnumFacing.WEST, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(-height, 0, min), new Vector3f(0, height, min),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.NORTH, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(-height, 0, max), new Vector3f(0, height, max),
renderColor, edgeUV,
sheet.edge, EnumFacing.SOUTH, rot, false
)
);
} else if (dir == EnumFacing.EAST) {
float[] topUV = new float[]{0, min, height, max};

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(16, height, min), new Vector3f(16 + height, height, max),
renderColor, topUV,
sheet.top[15], EnumFacing.UP, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(16 + height, 0, min), new Vector3f(16 + height, height, max),
renderColor, edgeUV,
sheet.top[15], EnumFacing.EAST, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(16, 0, min), new Vector3f(16 + height, height, min),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.NORTH, rot, false
)
);

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(16, 0, max), new Vector3f(16 + height, height, max),
renderColor, edgeUV,
sheet.edge, EnumFacing.SOUTH, rot, false
)
);
}
}

public void addWire(Wire wire, WireSheet sheet, List<BakedQuad> quads) {
WireFace side = wire.location;
int renderColor = wire.getRenderColor();

if (side == WireFace.CENTER) {
addWireFreestanding(wire, sheet, renderColor, quads);
return;
}

float min = 8.0f - (sheet.width / 2);
float max = 8.0f + (sheet.width / 2);
float minH = 0.0f;
float maxH = sheet.height;
EnumFacing[] dirs = WireUtils.getConnectionsForRender(side);

boolean[] connectionMatrix = new boolean[]{
wire == null || wire.connectsAny(dirs[0]),
wire == null || wire.connectsAny(dirs[1]),
wire == null || wire.connectsAny(dirs[2]),
wire == null || wire.connectsAny(dirs[3])
};
int cmc = (connectionMatrix[0] ? 8 : 0) | (connectionMatrix[1] ? 4 : 0) | (connectionMatrix[2] ? 2 : 0) | (connectionMatrix[3] ? 1 : 0);

boolean[] cornerConnectionMatrix = new boolean[]{
wire == null || wire.connectsCorner(dirs[0]),
wire == null || wire.connectsCorner(dirs[1]),
wire == null || wire.connectsCorner(dirs[2]),
wire == null || wire.connectsCorner(dirs[3])
};

ModelRotation rot = ROTATIONS[side.ordinal()];

// Center face

Vector3f from = new Vector3f(min, sheet.height, min);
Vector3f to = new Vector3f(max, sheet.height, max);

if (connectionMatrix[0]) {
from.setZ(0.0f);
}
if (connectionMatrix[1]) {
to.setZ(16.0f);
}
if (connectionMatrix[2]) {
from.setX(0.0f);
}
if (connectionMatrix[3]) {
to.setX(16.0f);
}

quads.add(
RenderUtils.BAKERY.makeBakedQuad(
from, to,
renderColor, new float[]{from.getX(), from.getZ(), to.getX(), to.getZ()},
sheet.top[cmc], EnumFacing.UP,
rot, true
)
);

from.setY(0.0F);
to.setY(0.0F);
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
from, to,
renderColor, new float[]{from.getX(), from.getZ(), to.getX(), to.getZ()},
sheet.top[cmc], EnumFacing.DOWN, rot, true
)
);


// Side faces
Vector3f fromZ = new Vector3f(from.getX(), 0.0f, min);
Vector3f toZ = new Vector3f(to.getX(), sheet.height, min);
Vector3f fromX = new Vector3f(min, 0.0f, from.getZ());
Vector3f toX = new Vector3f(min, sheet.height, to.getZ());

// Should we render a faux side wire on this side? (For bundled)
boolean crossroadsX = connectionMatrix[2] && !connectionMatrix[3];
boolean crossroadsZ = connectionMatrix[0] && !connectionMatrix[1];

// getIcon(false, cmc == 1, crossroadsX, EnumFacing.WEST)
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
fromX, toX,
renderColor, new float[]{fromX.getZ(), fromX.getY(), toX.getZ(), toX.getY()},
sheet.side, EnumFacing.WEST, rot, false
)
);

// getIcon(false, cmc == 0 || cmc == 4, crossroadsZ, EnumFacing.NORTH)
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
fromZ, toZ,
renderColor, new float[]{toZ.getX(), fromZ.getY(), fromZ.getX(), toZ.getY()},
sheet.side, EnumFacing.NORTH, rot, false
)
);

fromX.setX(max);
toX.setX(max);

fromZ.setZ(max);
toZ.setZ(max);

// getIcon(false, cmc == 2, crossroadsX, EnumFacing.EAST)
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
fromX, toX,
renderColor, new float[]{toX.getZ(), fromX.getY(), fromX.getZ(), toX.getY()},
sheet.side, EnumFacing.EAST, rot, false
)
);

// getIcon(false, cmc == 0 || cmc == 8, crossroadsZ, EnumFacing.SOUTH)
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
fromZ, toZ,
renderColor, new float[]{fromZ.getX(), fromZ.getY(), toZ.getX(), toZ.getY()},
sheet.side, EnumFacing.SOUTH, rot, false
)
);

// Edge faces
float[] edgeUV = new float[]{min, minH, max, maxH};
float[] edgeUVFlipped = new float[]{max, minH, min, maxH};

if (connectionMatrix[0]) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, minH, 0.0F), new Vector3f(max, maxH, 0.0F),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.NORTH, rot, false
)
);
}

if (connectionMatrix[1]) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(min, minH, 16.0F), new Vector3f(max, maxH, 16.0F),
renderColor, edgeUV,
sheet.edge, EnumFacing.SOUTH, rot, false
)
);
}

if (connectionMatrix[2]) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(0.0F, minH, min), new Vector3f(0.0F, maxH, max),
renderColor, edgeUV,
sheet.edge, EnumFacing.WEST, rot, false
)
);
}

if (connectionMatrix[3]) {
quads.add(
RenderUtils.BAKERY.makeBakedQuad(
new Vector3f(16.0F, minH, min), new Vector3f(16.0F, maxH, max),
renderColor, edgeUVFlipped,
sheet.edge, EnumFacing.EAST, rot, false
)
);
}

EnumFacing[] dirs0 = WireUtils.getConnectionsForRender(WireFace.DOWN);
for (int i = 0; i < 4; i++) {
if (cornerConnectionMatrix[i]) {
addCorner(wire, sheet, dirs0[i], renderColor, quads);
}
}
}

@Override
public IBakedModel bake(Wire wire, boolean isItem, BlockRenderLayer layer) {
WireSheet sheet = sheetMap.get(wire.getFactory());
SimpleBakedModel model = new SimpleBakedModel(this);
if (sheet != null) {
model.setParticle(sheet.particle);
addWire(wire, sheet, model.getQuads(null, null, 0));
}

return model;
}

@Override
public Wire fromItemStack(ItemStack stack) {
int md = stack.getItemDamage();
if (stackMap.containsKey(md)) {
return stackMap.get(md);
} else {
Wire wire = WireManager.ITEM.fromStack(stack, EnumFacing.DOWN);
wire.setConnectionsForItemRender();

stackMap.put(md, wire);
return wire;
}
}
}

+ 12
- 0
src/main/java/pl/asie/charset/lib/wires/TileWire.java View File

@@ -0,0 +1,12 @@
package pl.asie.charset.lib.wires;

import pl.asie.charset.api.wires.WireFace;
import pl.asie.charset.lib.blocks.TileBase;

public class TileWire extends TileBase {
private final Wire[] wires = new Wire[7];

protected Wire getWire(WireFace face) {
return wires[face.ordinal()];
}
}

+ 62
- 0
src/main/java/pl/asie/charset/lib/wires/Wire.java View File

@@ -0,0 +1,62 @@
package pl.asie.charset.lib.wires;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.common.util.INBTSerializable;
import pl.asie.charset.api.wires.WireFace;
import pl.asie.charset.lib.render.model.IRenderComparable;
import pl.asie.charset.lib.utils.UnlistedPropertyGeneric;

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

public abstract class Wire implements ICapabilityProvider, INBTSerializable<NBTTagCompound>, IRenderComparable<Wire> {
public static final IUnlistedProperty<Wire> PROPERTY = new UnlistedPropertyGeneric<>("wire", Wire.class);

protected final WireFactory factory;
public WireFace location;

protected Wire(WireFactory factory) {
this.factory = factory;
}

@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return false;
}

@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return null;
}

@Override
public NBTTagCompound serializeNBT() {
return null;
}

@Override
public void deserializeNBT(NBTTagCompound nbt) {

}

public abstract boolean connects(EnumFacing facing);

public WireFactory getFactory() {
return factory;
}

public int getRenderColor() {
return -1;
}

public abstract boolean connectsAny(EnumFacing dir);

public abstract boolean connectsCorner(EnumFacing dir);

public abstract void setConnectionsForItemRender();
}

+ 38
- 0
src/main/java/pl/asie/charset/lib/wires/WireFactory.java View File

@@ -0,0 +1,38 @@
package pl.asie.charset.lib.wires;

import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
import pl.asie.charset.api.wires.WireFace;

public abstract class WireFactory implements IForgeRegistryEntry<WireFactory> {
private ResourceLocation name;

public abstract Wire createPart(ItemStack stack);

public boolean canPlace(IBlockAccess access, BlockPos pos, WireFace face) {
return face == WireFace.CENTER || access.isSideSolid(pos.offset(face.facing), face.facing.getOpposite(), false);
}

public abstract float getWidth();
public abstract float getHeight();
public abstract ResourceLocation getTexturePrefix();

@Override
public WireFactory setRegistryName(ResourceLocation name) {
this.name = name;
return this;
}

@Override
public ResourceLocation getRegistryName() {
return name;
}

@Override
public Class<? super WireFactory> getRegistryType() {
return WireFactory.class;
}
}

+ 24
- 0
src/main/java/pl/asie/charset/lib/wires/WireManager.java View File

@@ -0,0 +1,24 @@
package pl.asie.charset.lib.wires;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.*;

public final class WireManager {
public static final IForgeRegistry<WireFactory> REGISTRY = new RegistryBuilder()
.setName(new ResourceLocation("charset:wire"))
.setIDRange(1, 255)
.setType(WireFactory.class)
.create();

public static ItemWire ITEM;

private WireManager() {

}

public static void register(WireFactory factory) {
REGISTRY.register(factory);
// TODO
// MultipartRegistry.registerPartFactory(factory, factory.getRegistryName().toString());
}
}

+ 24
- 0
src/main/java/pl/asie/charset/lib/wires/WireUtils.java View File

@@ -0,0 +1,24 @@
package pl.asie.charset.lib.wires;

import net.minecraft.util.EnumFacing;
import pl.asie.charset.api.wires.WireFace;

public final class WireUtils {
private static final EnumFacing[][] CONNECTION_DIRS = new EnumFacing[][]{
{EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.EAST},
{EnumFacing.SOUTH, EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.EAST},
{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.WEST, EnumFacing.EAST},
{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.WEST},
{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.SOUTH, EnumFacing.NORTH},
{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.SOUTH},
{EnumFacing.DOWN, EnumFacing.UP, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.EAST},
};

private WireUtils() {

}

public static EnumFacing[] getConnectionsForRender(WireFace face) {
return CONNECTION_DIRS[face.ordinal()];
}
}

+ 10
- 0
src/main/java/pl/asie/charset/misc/shelf/BlockShelf.java View File

@@ -140,6 +140,16 @@ public class BlockShelf extends BlockBase implements ITileEntityProvider {
.withProperty(BACK, meta >= 4);
}

public static EnumFacing getFace(EnumFacing facing, boolean back) {
return back ? facing.getOpposite() : facing;
}

public static EnumFacing getFacePlaced(EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
Vec3d placementVec = new Vec3d(hitX - 0.5F, hitY - 0.5F, hitZ - 0.5F).subtract(facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetZ());
placementVec = placementVec.rotateYaw(placer.getHorizontalFacing().getHorizontalAngle() / 180 * (float) Math.PI);
return getFace(placer.getHorizontalFacing(), placementVec.zCoord > 0);
}

@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
Vec3d placementVec = new Vec3d(hitX - 0.5F, hitY - 0.5F, hitZ - 0.5F).subtract(facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetZ());

+ 41
- 0
src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MCMPAddonMiscShelf.java View File

@@ -0,0 +1,41 @@
package pl.asie.charset.misc.shelf.modcompat.mcmultipart;

import mcmultipart.api.addon.IMCMPAddon;
import mcmultipart.api.addon.IWrappedBlock;
import mcmultipart.api.capability.MCMPCapabilities;
import mcmultipart.api.multipart.IMultipartRegistry;
import mcmultipart.api.multipart.IMultipartTile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import pl.asie.charset.lib.capability.CapabilityProviderFactory;
import pl.asie.charset.lib.modcompat.mcmultipart.CharsetMCMPAddon;
import pl.asie.charset.misc.shelf.CharsetMiscShelf;
import pl.asie.charset.misc.shelf.TileShelf;

@CharsetMCMPAddon("misc.shelf")
public class MCMPAddonMiscShelf implements IMCMPAddon {
private static final ResourceLocation KEY = new ResourceLocation("charset:pipeMultipart");
private CapabilityProviderFactory<IMultipartTile> factory;

public MCMPAddonMiscShelf() {
MinecraftForge.EVENT_BUS.register(this);
}

@Override
public void registerParts(IMultipartRegistry registry) {
registry.registerPartWrapper(CharsetMiscShelf.shelfBlock, new MultipartShelf());
IWrappedBlock pipeBlockWrapper = registry.registerStackWrapper(CharsetMiscShelf.shelfItem, (stack) -> true, CharsetMiscShelf.shelfBlock);
factory = new CapabilityProviderFactory<>(MCMPCapabilities.MULTIPART_TILE);
}

@SubscribeEvent
public void onAttachTile(AttachCapabilitiesEvent<TileEntity> event) {
if (event.getObject() instanceof TileShelf) {
final IMultipartTile multipartTile = new MultipartTileShelf((TileShelf) event.getObject());
event.addCapability(KEY, factory.create(multipartTile));
}
}
}

+ 34
- 0
src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MultipartShelf.java View File

@@ -0,0 +1,34 @@
package pl.asie.charset.misc.shelf.modcompat.mcmultipart;

import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import pl.asie.charset.lib.Properties;
import pl.asie.charset.misc.shelf.BlockShelf;
import pl.asie.charset.misc.shelf.CharsetMiscShelf;
import pl.asie.charset.pipes.CharsetPipes;

public class MultipartShelf implements IMultipart {
@Override
public Block getBlock() {
return CharsetMiscShelf.shelfBlock;
}

@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return EnumFaceSlot.fromFace(BlockShelf.getFacePlaced(facing, hitX, hitY, hitZ, placer));
}

@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return EnumFaceSlot.fromFace(BlockShelf.getFace(state.getValue(Properties.FACING4), state.getValue(BlockShelf.BACK)));
}
}

+ 11
- 0
src/main/java/pl/asie/charset/misc/shelf/modcompat/mcmultipart/MultipartTileShelf.java View File

@@ -0,0 +1,11 @@
package pl.asie.charset.misc.shelf.modcompat.mcmultipart;

import mcmultipart.api.multipart.IMultipartTile;
import pl.asie.charset.lib.modcompat.mcmultipart.MultipartTile;
import pl.asie.charset.misc.shelf.TileShelf;

public class MultipartTileShelf extends MultipartTile<TileShelf> {
public MultipartTileShelf(TileShelf owner) {
super(owner);
}
}

+ 5
- 3
src/main/java/pl/asie/charset/pipes/CharsetPipes.java View File

@@ -34,6 +34,7 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.ShapedOreRecipe;
import pl.asie.charset.ModCharset;
import pl.asie.charset.api.pipes.IShifter;
import pl.asie.charset.lib.annotation.CharsetModule;
import pl.asie.charset.lib.network.PacketRegistry;
@@ -57,7 +58,7 @@ import java.util.Random;
public class CharsetPipes {
public static final double PIPE_TESR_DISTANCE = 64.0D;

@SidedProxy(clientSide = "pl.asie.charset.pipes.ProxyClient", serverSide = "pl.asie.charset.pipes.ProxyCommon")
@SidedProxy(clientSide = "pl.asie.charset.pipes.ProxyClient", serverSide = "pl.asie.charset.pipes.ProxyCommon", modId = ModCharset.MODID)
public static ProxyCommon proxy;

@CapabilityInject(IShifter.class)
@@ -70,7 +71,8 @@ public class CharsetPipes {
public static CharsetPipes instance;

public static Block shifterBlock;
public static Block blockPipe;
public static BlockPipe blockPipe;
public static ItemBlock itemPipe;
public static final Random rand = new Random();

@Mod.EventHandler
@@ -78,7 +80,7 @@ public class CharsetPipes {
CapabilityManager.INSTANCE.register(IShifter.class, new ShifterStorage(), ShifterImpl.class);

blockPipe = new BlockPipe();
RegistryUtils.register(blockPipe, new ItemBlock(blockPipe),"pipe");
RegistryUtils.register(blockPipe, itemPipe = new ItemBlock(blockPipe),"pipe");
GameRegistry.registerTileEntityWithAlternatives(TilePipe.class, "charset:pipe", "charsetpipes:pipe");

shifterBlock = new BlockShifter();

+ 5
- 20
src/main/java/pl/asie/charset/pipes/PipeUtils.java View File

@@ -31,30 +31,15 @@ public final class PipeUtils {
public static TilePipe getPipe(TileEntity tile) {
if (tile == null)
return null;

return tile instanceof TilePipe ? (TilePipe) tile : (TilePipe) tile.getCapability(Capabilities.PIPE_VIEW, null);
if (tile instanceof TilePipe)
return (TilePipe) tile;
if (tile.hasCapability(Capabilities.PIPE_VIEW, null))
return (TilePipe) tile.getCapability(Capabilities.PIPE_VIEW, null);
return null;
}

public static TilePipe getPipe(IBlockAccess world, BlockPos blockPos, EnumFacing side) {
TileEntity tile = world.getTileEntity(blockPos);
return getPipe(tile);
/* IMultipartContainer ui = MultipartHelper.getPartContainer(world, blockPos);
if (ui == null) {
return null;
}

if (side != null) {
ISlottedPart part = ui.getPartInSlot(PartSlot.getFaceSlot(side));
if (part instanceof IMicroblock.IFaceMicroblock && !((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
return null;
}
}

ISlottedPart part = ui.getPartInSlot(PartSlot.CENTER);
if (part instanceof TilePipe) {
return (TilePipe) part;