1.2
continuous-integration/drone Build is failing
Details
continuous-integration/drone Build is failing
Details
-Merged Exposer with Expose
This commit is contained in:
parent
a4a3aac818
commit
b7eff37221
|
@ -1,5 +1,5 @@
|
|||
modGroup=ley.anvil
|
||||
modVersion=1.0
|
||||
modVersion=1.2
|
||||
modBaseName=exposer
|
||||
forgeVersion=1.12.2-14.23.5.2847
|
||||
mcpVersion=stable_39
|
||||
|
|
|
@ -18,7 +18,8 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
|||
modid = Exposer.MOD_ID,
|
||||
name = Exposer.MOD_NAME,
|
||||
version = Exposer.VERSION,
|
||||
dependencies = "required-after:refinedstorage"
|
||||
dependencies = "required-after:refinedstorage",
|
||||
acceptableRemoteVersions = "*"
|
||||
)
|
||||
public class Exposer {
|
||||
|
||||
|
@ -26,86 +27,26 @@ public class Exposer {
|
|||
public static final String MOD_NAME = "Exposer";
|
||||
public static final String VERSION = "${version}";
|
||||
|
||||
/**
|
||||
* This is the instance of your mod as created by Forge. It will never be null.
|
||||
*/
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static Exposer INSTANCE;
|
||||
|
||||
/**
|
||||
* This is the first initialization event. Register tile entities here.
|
||||
* The registry events below will have fired prior to entry to this method.
|
||||
*/
|
||||
@Mod.EventHandler
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
GameRegistry.registerTileEntity(TileExposer.class, new ResourceLocation(MOD_ID, "exposer"));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the second initialization event. Register custom recipes
|
||||
*/
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the final initialization event. Register actions from other mods here
|
||||
*/
|
||||
@Mod.EventHandler
|
||||
public void postinit(FMLPostInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Forge will automatically look up and bind blocks to the fields in this class
|
||||
* based on their registry name.
|
||||
*/
|
||||
@GameRegistry.ObjectHolder(MOD_ID)
|
||||
public static class Blocks {
|
||||
public static final BlockExposer exposer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forge will automatically look up and bind items to the fields in this class
|
||||
* based on their registry name.
|
||||
*/
|
||||
@GameRegistry.ObjectHolder(MOD_ID)
|
||||
public static class Items {
|
||||
/*
|
||||
public static final ItemBlock mySpecialBlock = null; // itemblock for the block above
|
||||
public static final MySpecialItem mySpecialItem = null; // placeholder for special item below
|
||||
*/
|
||||
public static final ItemBlock exposer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a special class that listens to registry events, to allow creation of mod blocks and items at the proper time.
|
||||
*/
|
||||
@Mod.EventBusSubscriber
|
||||
public static class ObjectRegistryHandler {
|
||||
/**
|
||||
* Listen for the register event for creating custom items
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void addItems(RegistryEvent.Register<Item> event) {
|
||||
/*
|
||||
event.getRegistry().register(new ItemBlock(Blocks.myBlock).setRegistryName(MOD_ID, "myBlock"));
|
||||
event.getRegistry().register(new MySpecialItem().setRegistryName(MOD_ID, "mySpecialItem"));
|
||||
*/
|
||||
event.getRegistry().register(new ItemBlock(Blocks.exposer).setRegistryName(new ResourceLocation(MOD_ID, BlockExposer.ID)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for the register event for creating custom blocks
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void addBlocks(RegistryEvent.Register<Block> event) {
|
||||
/*
|
||||
event.getRegistry().register(new MySpecialBlock().setRegistryName(MOD_ID, "mySpecialBlock"));
|
||||
*/
|
||||
event.getRegistry().register(new BlockExposer());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package ley.anvil.exposer;
|
||||
|
||||
import ley.anvil.exposer.block.BlockExposer;
|
||||
import ley.anvil.exposer.config.ModConfig;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class Registry {
|
||||
|
||||
@GameRegistry.ObjectHolder(Exposer.MOD_ID)
|
||||
public static class Blocks {
|
||||
public static final BlockExposer exposer = null;
|
||||
}
|
||||
|
||||
@GameRegistry.ObjectHolder(Exposer.MOD_ID)
|
||||
public static class Items {
|
||||
public static final ItemBlock exposer = null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void addItems(RegistryEvent.Register<Item> event) {
|
||||
if (ModConfig.exposer)
|
||||
event.getRegistry().register(new ItemBlock(Blocks.exposer).setRegistryName(new ResourceLocation(Exposer.MOD_ID, BlockExposer.ID)));
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void addBlocks(RegistryEvent.Register<Block> event) {
|
||||
if (ModConfig.exposer)
|
||||
event.getRegistry().register(new BlockExposer());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package ley.anvil.exposer.cap;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.tile.TileController;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileExternalStorage;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CoreCapProvider implements ICapabilityProvider {
|
||||
|
||||
TileController core;
|
||||
ItemHandlerExposer handler;
|
||||
|
||||
public CoreCapProvider(TileController core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
if (facing != null) {
|
||||
BlockPos pos = core.getPos().offset(facing);
|
||||
if (core.getWorld().isBlockLoaded(pos)) {
|
||||
TileEntity te = core.getWorld().getTileEntity(pos);
|
||||
if (te instanceof TileExternalStorage) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
return true;
|
||||
}
|
||||
else if (core.getItemStorageCache() != null){
|
||||
handler = new ItemHandlerExposer(core);
|
||||
core.getItemStorageCache().addListener(handler);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (hasCapability(capability, facing)) {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(handler);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package ley.anvil.exposer.cap;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.tile.TileExternalStorage;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.TileGrid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridCapProvider implements ICapabilityProvider {
|
||||
|
||||
TileGrid grid;
|
||||
TileEntity core;
|
||||
|
||||
public GridCapProvider(TileGrid grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && grid.getNode().getNetwork() instanceof TileEntity) {
|
||||
if (facing != null) {
|
||||
BlockPos pos = grid.getPos().offset(facing);
|
||||
if (grid.getWorld().isBlockLoaded(pos)) {
|
||||
TileEntity te = grid.getWorld().getTileEntity(pos);
|
||||
if (te instanceof TileExternalStorage) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (core == null || !grid.getNode().isActive()) {
|
||||
core = (TileEntity) grid.getNode().getNetwork();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (hasCapability(capability, facing)) {
|
||||
return core.getCapability(capability, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
package ley.anvil.exposer.node;
|
||||
package ley.anvil.exposer.cap;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemHandlerExposer implements IItemHandler, IStorageCacheListener<ItemStack> {
|
||||
|
||||
|
@ -75,4 +76,11 @@ public class ItemHandlerExposer implements IItemHandler, IStorageCacheListener<I
|
|||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
public void onChangedBulk(@Nonnull List<Pair<ItemStack, Integer>> stacks) {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package ley.anvil.exposer.config;
|
||||
|
||||
import ley.anvil.exposer.Exposer;
|
||||
import net.minecraftforge.common.config.Config;
|
||||
|
||||
@Config(modid = Exposer.MOD_ID)
|
||||
public class ModConfig {
|
||||
|
||||
@Config.Name("Grid Expose")
|
||||
@Config.Comment("Should the Grid expose the networks contents? (requires Enable Exposing to be true)")
|
||||
public static boolean gridExpose = true;
|
||||
|
||||
@Config.Name("Enable Exposer")
|
||||
@Config.Comment("Enables the Exposer block. Needs also to be on the client if true.")
|
||||
public static boolean exposer = true;
|
||||
|
||||
@Config.Name("Enable Exposing")
|
||||
@Config.Comment("Enables the Controller to expose the network.")
|
||||
public static boolean expose = true;
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package ley.anvil.exposer.event;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.tile.TileController;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.TileGrid;
|
||||
import ley.anvil.exposer.Exposer;
|
||||
import ley.anvil.exposer.cap.CoreCapProvider;
|
||||
import ley.anvil.exposer.cap.GridCapProvider;
|
||||
import ley.anvil.exposer.config.ModConfig;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = Exposer.MOD_ID)
|
||||
public class EventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAttachCapabilities(AttachCapabilitiesEvent<TileEntity> event) {
|
||||
if (event.getObject() instanceof TileController && ModConfig.expose) {
|
||||
event.addCapability(new ResourceLocation(Exposer.MOD_ID, "coreexpose"), new CoreCapProvider((TileController) event.getObject()));
|
||||
} else if (event.getObject() instanceof TileGrid && ModConfig.gridExpose && ModConfig.expose) {
|
||||
event.addCapability(new ResourceLocation(Exposer.MOD_ID, "gridexpose"), new GridCapProvider((TileGrid) event.getObject()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package ley.anvil.exposer.node;
|
|||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||
import ley.anvil.exposer.cap.ItemHandlerExposer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"model": "exposer:exposer"
|
||||
},
|
||||
"variants": {
|
||||
"normal": [{}],
|
||||
"inventory": [{}]
|
||||
"normal": [{"model": "exposer:exposer"}],
|
||||
"inventory": [{"model": "exposer:exposer"}]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue