Re-add the portable grid (block form)
This commit is contained in:
@@ -85,22 +85,19 @@ public class ClientSetup {
|
||||
new ResourceLocation(RS.ID, "block/disks/leds")
|
||||
).disableCache());
|
||||
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "portable_grid"), (base, registry) -> new PortableGridBakedModel(
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_connected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_disconnected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_near_capacity")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_full")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_disconnected"))
|
||||
));
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "creative_portable_grid"), (base, registry) -> new PortableGridBakedModel(
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_connected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_disconnected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_near_capacity")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_full")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_disconnected"))
|
||||
));
|
||||
for (String portableGridName : new String[]{"portable_grid", "creative_portable_grid"}) {
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, portableGridName), (base, registry) -> new FullbrightBakedModel(
|
||||
new PortableGridBakedModel(
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_connected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/portable_grid_disconnected")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_near_capacity")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_full")),
|
||||
registry.get(new ResourceLocation(RS.ID + ":block/disks/portable_grid_disk_disconnected"))
|
||||
),
|
||||
new ResourceLocation(RS.ID + ":block/disks/leds")
|
||||
).disableCache());
|
||||
}
|
||||
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "pattern"), (base, registry) -> new PatternBakedModel(base));
|
||||
|
||||
|
@@ -7,10 +7,7 @@ import com.raoulvdberge.refinedstorage.api.storage.StorageType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkListener;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeListener;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.GridBlockGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.PortableGridGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.WirelessFluidGridGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.WirelessGridGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator.DiskManipulatorNetworkNode;
|
||||
@@ -32,12 +29,14 @@ import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainer
|
||||
import com.raoulvdberge.refinedstorage.item.*;
|
||||
import com.raoulvdberge.refinedstorage.item.blockitem.*;
|
||||
import com.raoulvdberge.refinedstorage.item.group.MainItemGroup;
|
||||
import com.raoulvdberge.refinedstorage.loottable.PortableGridBlockLootFunctionSerializer;
|
||||
import com.raoulvdberge.refinedstorage.loottable.StorageBlockLootFunctionSerializer;
|
||||
import com.raoulvdberge.refinedstorage.network.NetworkHandler;
|
||||
import com.raoulvdberge.refinedstorage.recipe.UpgradeWithEnchantedBookRecipeSerializer;
|
||||
import com.raoulvdberge.refinedstorage.tile.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.GridTile;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -137,11 +136,13 @@ public final class RS {
|
||||
API.instance().getGridManager().add(WirelessGridGridFactory.ID, new WirelessGridGridFactory());
|
||||
API.instance().getGridManager().add(WirelessFluidGridGridFactory.ID, new WirelessFluidGridGridFactory());
|
||||
API.instance().getGridManager().add(PortableGridGridFactory.ID, new PortableGridGridFactory());
|
||||
API.instance().getGridManager().add(PortableGridBlockGridFactory.ID, new PortableGridBlockGridFactory());
|
||||
|
||||
API.instance().addExternalStorageProvider(StorageType.ITEM, new ItemExternalStorageProvider());
|
||||
API.instance().addExternalStorageProvider(StorageType.FLUID, new FluidExternalStorageProvider());
|
||||
|
||||
LootFunctionManager.registerFunction(new StorageBlockLootFunctionSerializer());
|
||||
LootFunctionManager.registerFunction(new PortableGridBlockLootFunctionSerializer());
|
||||
}
|
||||
|
||||
private INetworkNode readAndReturn(CompoundNBT tag, NetworkNode node) {
|
||||
@@ -233,6 +234,9 @@ public final class RS {
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(ConstructorTile::new, RSBlocks.CONSTRUCTOR).build(null).setRegistryName(RS.ID, "constructor")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(DestructorTile::new, RSBlocks.DESTRUCTOR).build(null).setRegistryName(RS.ID, "destructor")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(DiskManipulatorTile::new, RSBlocks.DISK_MANIPULATOR).build(null).setRegistryName(RS.ID, "disk_manipulator")));
|
||||
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new PortableGridTile(PortableGridBlockItem.Type.CREATIVE), RSBlocks.CREATIVE_PORTABLE_GRID).build(null).setRegistryName(RS.ID, "creative_portable_grid")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new PortableGridTile(PortableGridBlockItem.Type.NORMAL), RSBlocks.PORTABLE_GRID).build(null).setRegistryName(RS.ID, "portable_grid")));
|
||||
}
|
||||
|
||||
private <T extends TileEntity> TileEntityType<T> registerTileDataParameters(TileEntityType<T> t) {
|
||||
|
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage;
|
||||
import com.raoulvdberge.refinedstorage.tile.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.GridTile;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
@@ -74,9 +74,11 @@ public class RSTiles {
|
||||
public static final TileEntityType<DestructorTile> DESTRUCTOR = null;
|
||||
@ObjectHolder(RS.ID + ":disk_manipulator")
|
||||
public static final TileEntityType<DiskManipulatorTile> DISK_MANIPULATOR = null;
|
||||
@ObjectHolder(RS.ID + ":portable_grid")
|
||||
public static final TileEntityType<PortableGridTile> PORTABLE_GRID = null;
|
||||
@ObjectHolder(RS.ID + ":creative_portable_grid")
|
||||
public static final TileEntityType<PortableGridTile> CREATIVE_PORTABLE_GRID = null;
|
||||
|
||||
//@ObjectHolder(RS.ID + ":portable_grid")
|
||||
public static final TileEntityType<TilePortableGrid> PORTABLE_GRID = null;
|
||||
//@ObjectHolder(RS.ID + ":crafter")
|
||||
public static final TileEntityType<TileCrafter> CRAFTER = null;
|
||||
//@ObjectHolder(RS.ID + ":crafter_manager")
|
||||
|
@@ -1,18 +1,22 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PortableGridBlockGridFactory implements IGridFactory {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "portable_grid_block");
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IGrid createFromStack(PlayerEntity player, ItemStack stack) {
|
||||
@@ -24,8 +28,8 @@ public class PortableGridBlockGridFactory implements IGridFactory {
|
||||
public IGrid createFromBlock(PlayerEntity player, BlockPos pos) {
|
||||
TileEntity tile = getRelevantTile(player.world, pos);
|
||||
|
||||
if (tile instanceof TilePortableGrid) {
|
||||
return (TilePortableGrid) tile;
|
||||
if (tile instanceof PortableGridTile) {
|
||||
return (PortableGridTile) tile;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -1,17 +1,38 @@
|
||||
package com.raoulvdberge.refinedstorage.block;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.block.enums.PortableGridType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.PortableGridBlockGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
|
||||
import com.raoulvdberge.refinedstorage.item.blockitem.PortableGridBlockItem;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridDiskState;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PortableGridBlock extends BaseBlock {
|
||||
public static final EnumProperty<PortableGridType> TYPE = EnumProperty.create("type", PortableGridType.class);
|
||||
public static final EnumProperty<PortableGridDiskState> DISK_STATE = EnumProperty.create("disk_state", PortableGridDiskState.class);
|
||||
public static final BooleanProperty CONNECTED = BooleanProperty.create("connected");
|
||||
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
||||
|
||||
private static final VoxelShape SHAPE = makeCuboidShape(0, 0, 0, 16, 13.2, 16);
|
||||
|
||||
private final PortableGridBlockItem.Type type;
|
||||
|
||||
@@ -20,105 +41,58 @@ public class PortableGridBlock extends BaseBlock {
|
||||
|
||||
this.type = type;
|
||||
this.setRegistryName(RS.ID, (type == PortableGridBlockItem.Type.CREATIVE ? "creative_" : "") + "portable_grid");
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void registerModels(IModelRegistration modelRegistration) {
|
||||
modelRegistration.setStateMapper(this, new StateMap.Builder().ignore(TYPE).build());
|
||||
modelRegistration.setModelMeshDefinition(this, new ItemMeshDefinitionPortableGrid());
|
||||
|
||||
modelRegistration.addBakedModelOverride(info.getId(), base -> new BakedModelFullbright(
|
||||
base,
|
||||
RS.ID + ":blocks/disks/leds"
|
||||
));
|
||||
this.setDefaultState(getDefaultState().with(DISK_STATE, PortableGridDiskState.NONE).with(ACTIVE, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||
super.fillStateContainer(builder);
|
||||
|
||||
builder.add(DISK_STATE);
|
||||
builder.add(ACTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockDirection getDirection() {
|
||||
return BlockDirection.HORIZONTAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item createItem() {
|
||||
return new ItemBlockPortableGrid(this);
|
||||
public boolean hasTileEntity(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<CollisionGroup> getCollisions(TileEntity tile, BlockState state) {
|
||||
return Collections.singletonList(ConstantsPortableGrid.COLLISION);
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new PortableGridTile(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isOpaqueCube(BlockState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isFullCube(BlockState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||
|
||||
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
((TilePortableGrid) world.getTileEntity(pos)).onPassItemContext(stack);
|
||||
}
|
||||
}
|
||||
API.instance().getGridManager().openGrid(PortableGridBlockGridFactory.ID, (ServerPlayerEntity) player, pos);
|
||||
|
||||
@Override
|
||||
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, BlockState state, int fortune) {
|
||||
drops.add(((TilePortableGrid) world.getTileEntity(pos)).getAsItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getActualState(BlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TilePortableGrid portableGrid = (TilePortableGrid) world.getTileEntity(pos);
|
||||
|
||||
return super.getActualState(state, world, pos)
|
||||
.withProperty(DISK_STATE, portableGrid.getDiskState())
|
||||
.withProperty(CONNECTED, portableGrid.isConnected());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return createBlockStateBuilder()
|
||||
.add(TYPE)
|
||||
.add(DISK_STATE)
|
||||
.add(CONNECTED)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(TYPE, meta == 0 ? PortableGridType.NORMAL : PortableGridType.CREATIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(BlockState state) {
|
||||
return state.getValue(TYPE) == PortableGridType.NORMAL ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
|
||||
if (!world.isRemote) {
|
||||
API.instance().getGridManager().openGrid(TilePortableGrid.FACTORY_ID, (ServerPlayerEntity) player, pos);
|
||||
|
||||
((TilePortableGrid) world.getTileEntity(pos)).onOpened();
|
||||
((PortableGridTile) world.getTileEntity(pos)).onOpened();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, BlockState state, BlockPos pos, Direction face) {
|
||||
return BlockFaceShape.UNDEFINED;
|
||||
}*/
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||
|
||||
if (!world.isRemote) {
|
||||
((PortableGridTile) world.getTileEntity(pos)).applyDataFromItemToTile(stack);
|
||||
((PortableGridTile) world.getTileEntity(pos)).updateState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.block.enums;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum PortableGridType implements IStringSerializable {
|
||||
NORMAL(0, "normal"),
|
||||
CREATIVE(1, "creative");
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
PortableGridType(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.raoulvdberge.refinedstorage.loottable;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraft.world.storage.loot.functions.ILootFunction;
|
||||
|
||||
public class PortableGridBlockLootFunction implements ILootFunction {
|
||||
@Override
|
||||
public ItemStack apply(ItemStack stack, LootContext lootContext) {
|
||||
TileEntity tile = lootContext.get(LootParameters.BLOCK_ENTITY);
|
||||
|
||||
if (tile instanceof PortableGridTile) {
|
||||
((PortableGridTile) tile).applyDataFromTileToItem(stack);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.raoulvdberge.refinedstorage.loottable;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.functions.ILootFunction;
|
||||
|
||||
public class PortableGridBlockLootFunctionSerializer extends ILootFunction.Serializer<PortableGridBlockLootFunction> {
|
||||
public PortableGridBlockLootFunctionSerializer() {
|
||||
super(new ResourceLocation(RS.ID, "portable_grid"), PortableGridBlockLootFunction.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonObject jsonObject, PortableGridBlockLootFunction function, JsonSerializationContext jsonSerializationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortableGridBlockLootFunction deserialize(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
|
||||
return new PortableGridBlockLootFunction();
|
||||
}
|
||||
}
|
@@ -7,8 +7,6 @@ public class ProxyCommon {
|
||||
|
||||
API.deliver(e.getAsmData());
|
||||
|
||||
TilePortableGrid.FACTORY_ID = API.instance().getGridManager().add(new GridFactoryPortableGridBlock());
|
||||
|
||||
API.instance().getCraftingTaskRegistry().add(CraftingTaskFactory.ID, new CraftingTaskFactory());
|
||||
|
||||
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementItemRender.ID, buf -> new CraftingMonitorElementItemRender(StackUtils.readItemStack(buf), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt()));
|
||||
|
@@ -1,8 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.render.constants;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
public final class ConstantsPortableGrid {
|
||||
public static final CollisionGroup COLLISION = new CollisionGroup().addItem(new AxisAlignedBB(0, 0, 0, 1, 13.2F / 16F, 1));
|
||||
}
|
@@ -1,13 +1,26 @@
|
||||
package com.raoulvdberge.refinedstorage.render.model;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.block.PortableGridBlock;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridDiskState;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class PortableGridBakedModel extends DelegateBakedModel {
|
||||
private final IBakedModel baseConnected;
|
||||
@@ -19,6 +32,39 @@ public class PortableGridBakedModel extends DelegateBakedModel {
|
||||
|
||||
private final CustomItemOverrideList itemOverrideList = new CustomItemOverrideList();
|
||||
|
||||
private LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public List<BakedQuad> load(CacheKey key) {
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
|
||||
if (key.active) {
|
||||
quads.addAll(new TRSRBakedModel(baseConnected, key.direction).getQuads(key.state, key.side, key.random));
|
||||
} else {
|
||||
quads.addAll(new TRSRBakedModel(baseDisconnected, key.direction).getQuads(key.state, key.side, key.random));
|
||||
}
|
||||
|
||||
switch (key.diskState) {
|
||||
case NORMAL:
|
||||
quads.addAll(new TRSRBakedModel(disk, key.direction).getQuads(key.state, key.side, key.random));
|
||||
break;
|
||||
case NEAR_CAPACITY:
|
||||
quads.addAll(new TRSRBakedModel(diskNearCapacity, key.direction).getQuads(key.state, key.side, key.random));
|
||||
break;
|
||||
case FULL:
|
||||
quads.addAll(new TRSRBakedModel(diskFull, key.direction).getQuads(key.state, key.side, key.random));
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
quads.addAll(new TRSRBakedModel(diskDisconnected, key.direction).getQuads(key.state, key.side, key.random));
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
return quads;
|
||||
}
|
||||
});
|
||||
|
||||
public PortableGridBakedModel(IBakedModel baseConnected,
|
||||
IBakedModel baseDisconnected,
|
||||
IBakedModel disk,
|
||||
@@ -40,6 +86,19 @@ public class PortableGridBakedModel extends DelegateBakedModel {
|
||||
return itemOverrideList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
if (state != null) {
|
||||
Direction direction = state.get(RSBlocks.PORTABLE_GRID.getDirection().getProperty());
|
||||
boolean active = state.get(PortableGridBlock.ACTIVE);
|
||||
PortableGridDiskState diskState = state.get(PortableGridBlock.DISK_STATE);
|
||||
|
||||
return cache.getUnchecked(new CacheKey(direction, diskState, active, rand, state, side));
|
||||
}
|
||||
|
||||
return super.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
private class CustomItemOverrideList extends ItemOverrideList {
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -72,4 +131,37 @@ public class PortableGridBakedModel extends DelegateBakedModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CacheKey {
|
||||
private final Direction direction;
|
||||
private final PortableGridDiskState diskState;
|
||||
private final boolean active;
|
||||
private final Random random;
|
||||
private final BlockState state;
|
||||
private final Direction side;
|
||||
|
||||
public CacheKey(Direction direction, PortableGridDiskState diskState, boolean active, Random random, BlockState state, Direction side) {
|
||||
this.direction = direction;
|
||||
this.diskState = diskState;
|
||||
this.active = active;
|
||||
this.random = random;
|
||||
this.state = state;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CacheKey cacheKey = (CacheKey) o;
|
||||
return active == cacheKey.active &&
|
||||
direction == cacheKey.direction &&
|
||||
diskState == cacheKey.diskState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(direction, diskState, active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import com.raoulvdberge.refinedstorage.tile.config.IType;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.GridTile;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGridTile;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.TimeUtils;
|
||||
import net.minecraft.client.audio.SimpleSound;
|
||||
@@ -94,8 +94,8 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
|
||||
this.scrollbar = new ScrollbarWidget(this, 174, getTopHeight(), 12, (getVisibleRows() * 18) - 2);
|
||||
|
||||
if (grid instanceof GridNetworkNode || grid instanceof TilePortableGrid) {
|
||||
addSideButton(new RedstoneModeSideButton(this, grid instanceof GridNetworkNode ? GridTile.REDSTONE_MODE : TilePortableGrid.REDSTONE_MODE));
|
||||
if (grid instanceof GridNetworkNode || grid instanceof PortableGridTile) {
|
||||
addSideButton(new RedstoneModeSideButton(this, grid instanceof GridNetworkNode ? GridTile.REDSTONE_MODE : PortableGridTile.REDSTONE_MODE));
|
||||
}
|
||||
|
||||
int sx = x + 80 + 1;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSTiles;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridListener;
|
||||
@@ -20,6 +20,7 @@ import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.DiskState;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.PortableFluidStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.PortableItemStorageCache;
|
||||
@@ -30,12 +31,12 @@ import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.PortableItemStorageD
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.tracker.FluidStorageTracker;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.tracker.ItemStorageTracker;
|
||||
import com.raoulvdberge.refinedstorage.block.PortableGridBlock;
|
||||
import com.raoulvdberge.refinedstorage.block.enums.PortableGridType;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.BaseItemHandler;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.FilterItemHandler;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.validator.StorageDiskItemValidator;
|
||||
import com.raoulvdberge.refinedstorage.inventory.listener.TileInventoryListener;
|
||||
import com.raoulvdberge.refinedstorage.item.WirelessGridItem;
|
||||
import com.raoulvdberge.refinedstorage.item.blockitem.PortableGridBlockItem;
|
||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||
import com.raoulvdberge.refinedstorage.tile.BaseTile;
|
||||
@@ -46,7 +47,6 @@ import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.GridTile;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.CraftResultInventory;
|
||||
@@ -73,56 +73,52 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageDiskContainerContext {
|
||||
public static int FACTORY_ID;
|
||||
|
||||
public static final TileDataParameter<Integer, TilePortableGrid> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored());
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingDirection, (t, v) -> {
|
||||
public class PortableGridTile extends BaseTile implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageDiskContainerContext {
|
||||
public static final TileDataParameter<Integer, PortableGridTile> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||
private static final TileDataParameter<Integer, PortableGridTile> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getSortingDirection, (t, v) -> {
|
||||
if (IGrid.isValidSortingDirection(v)) {
|
||||
t.setSortingDirection(v);
|
||||
t.markDirty();
|
||||
}
|
||||
}, (initial, p) -> GridTile.trySortGrid(initial));
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> SORTING_TYPE = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingType, (t, v) -> {
|
||||
private static final TileDataParameter<Integer, PortableGridTile> SORTING_TYPE = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getSortingType, (t, v) -> {
|
||||
if (IGrid.isValidSortingType(v)) {
|
||||
t.setSortingType(v);
|
||||
t.markDirty();
|
||||
}
|
||||
}, (initial, p) -> GridTile.trySortGrid(initial));
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> SEARCH_BOX_MODE = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSearchBoxMode, (t, v) -> {
|
||||
private static final TileDataParameter<Integer, PortableGridTile> SEARCH_BOX_MODE = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getSearchBoxMode, (t, v) -> {
|
||||
if (IGrid.isValidSearchBoxMode(v)) {
|
||||
t.setSearchBoxMode(v);
|
||||
t.markDirty();
|
||||
}
|
||||
}, (initial, p) -> BaseScreen.executeLater(GridScreen.class, grid -> grid.getSearchField().setMode(p)));
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> SIZE = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSize, (t, v) -> {
|
||||
private static final TileDataParameter<Integer, PortableGridTile> SIZE = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getSize, (t, v) -> {
|
||||
if (IGrid.isValidSize(v)) {
|
||||
t.setSize(v);
|
||||
t.markDirty();
|
||||
}
|
||||
}, (initial, p) -> BaseScreen.executeLater(GridScreen.class, BaseScreen::init));
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> TAB_SELECTED = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getTabSelected, (t, v) -> {
|
||||
private static final TileDataParameter<Integer, PortableGridTile> TAB_SELECTED = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getTabSelected, (t, v) -> {
|
||||
t.setTabSelected(v == t.getTabSelected() ? -1 : v);
|
||||
t.markDirty();
|
||||
}, (initial, p) -> BaseScreen.executeLater(GridScreen.class, grid -> grid.getView().sort()));
|
||||
private static final TileDataParameter<Integer, TilePortableGrid> TAB_PAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getTabPage, (t, v) -> {
|
||||
private static final TileDataParameter<Integer, PortableGridTile> TAB_PAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, PortableGridTile::getTabPage, (t, v) -> {
|
||||
if (v >= 0 && v <= t.getTotalTabPages()) {
|
||||
t.setTabPage(v);
|
||||
t.markDirty();
|
||||
}
|
||||
});
|
||||
|
||||
private static final String NBT_ENERGY = "Energy";
|
||||
private static final String NBT_DISK_STATE = "DiskState";
|
||||
private static final String NBT_CONNECTED = "Connected";
|
||||
private static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
||||
private static final String NBT_FLUID_STORAGE_TRACKER = "FluidStorageTracker";
|
||||
private static final String NBT_TYPE = "Type";
|
||||
private static final String NBT_ENERGY = "Energy";
|
||||
private static final String NBT_ENCHANTMENTS = "ench"; // @Volatile: minecraft specific nbt key
|
||||
private EnergyStorage energyStorage = recreateEnergyStorage(0);
|
||||
private EnergyStorage energyStorage = createEnergyStorage(0);
|
||||
private LazyOptional<EnergyStorage> energyStorageCap = LazyOptional.of(() -> energyStorage);
|
||||
private PortableGridType type;
|
||||
|
||||
private PortableGridBlockItem.Type type;
|
||||
|
||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||
|
||||
@@ -145,6 +141,12 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
.addListener((handler, slot, reading) -> {
|
||||
if (world != null && !world.isRemote) {
|
||||
loadStorage();
|
||||
|
||||
if (!reading) {
|
||||
updateState();
|
||||
|
||||
WorldUtils.updateBlock(world, pos); // Re-send grid type
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -155,18 +157,21 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
|
||||
private PortableItemGridHandler itemHandler = new PortableItemGridHandler(this, this);
|
||||
private PortableFluidGridHandler fluidHandler = new PortableFluidGridHandler(this);
|
||||
|
||||
private PortableGridDiskState diskState = PortableGridDiskState.NONE;
|
||||
private boolean connected;
|
||||
private boolean active;
|
||||
|
||||
private ItemStorageTracker storageTracker = new ItemStorageTracker(this::markDirty);
|
||||
private FluidStorageTracker fluidStorageTracker = new FluidStorageTracker(this::markDirty);
|
||||
|
||||
private ListNBT enchants = null;
|
||||
|
||||
public TilePortableGrid() {
|
||||
super(RSTiles.PORTABLE_GRID);
|
||||
public PortableGridTile(PortableGridBlockItem.Type type) {
|
||||
super(type == PortableGridBlockItem.Type.CREATIVE ? RSTiles.CREATIVE_PORTABLE_GRID : RSTiles.PORTABLE_GRID);
|
||||
|
||||
this.type = type;
|
||||
|
||||
dataManager.addWatchedParameter(REDSTONE_MODE);
|
||||
dataManager.addWatchedParameter(ENERGY_STORED);
|
||||
dataManager.addWatchedParameter(SORTING_DIRECTION);
|
||||
dataManager.addWatchedParameter(SORTING_TYPE);
|
||||
dataManager.addWatchedParameter(SEARCH_BOX_MODE);
|
||||
@@ -198,7 +203,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
break;
|
||||
}
|
||||
|
||||
this.storage.setSettings(TilePortableGrid.this::checkIfDiskStateChanged, TilePortableGrid.this);
|
||||
this.storage.setSettings(PortableGridTile.this::updateState, PortableGridTile.this);
|
||||
} else {
|
||||
this.storage = null;
|
||||
this.cache = null;
|
||||
@@ -208,29 +213,19 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
if (cache != null) {
|
||||
cache.invalidate();
|
||||
}
|
||||
|
||||
checkIfDiskStateChanged();
|
||||
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
this.loadStorage();
|
||||
|
||||
active = isActive();
|
||||
diskState = getDiskState();
|
||||
}
|
||||
|
||||
public PortableGridType getPortableType() {
|
||||
if (type == null) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
|
||||
if (state.getBlock() == RSBlocks.PORTABLE_GRID) {
|
||||
this.type = state.get(PortableGridBlock.TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
return type == null ? PortableGridType.NORMAL : type;
|
||||
}
|
||||
|
||||
public void onPassItemContext(ItemStack stack) {
|
||||
public void applyDataFromItemToTile(ItemStack stack) {
|
||||
this.sortingType = WirelessGridItem.getSortingType(stack);
|
||||
this.sortingDirection = WirelessGridItem.getSortingDirection(stack);
|
||||
this.searchBoxMode = WirelessGridItem.getSearchBoxMode(stack);
|
||||
@@ -240,7 +235,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
|
||||
IEnergyStorage energyStorage = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null);
|
||||
|
||||
this.energyStorage = recreateEnergyStorage(energyStorage != null ? energyStorage.getEnergyStored() : 0);
|
||||
this.energyStorage = createEnergyStorage(energyStorage != null ? energyStorage.getEnergyStored() : 0);
|
||||
|
||||
if (stack.hasTag()) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@@ -264,19 +259,10 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
}
|
||||
}
|
||||
|
||||
this.diskState = getDiskState();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
private EnergyStorage recreateEnergyStorage(int energyStored) {
|
||||
return null;
|
||||
// TODO return new EnergyStorage(RS.INSTANCE.config.portableGridCapacity, RS.INSTANCE.config.portableGridCapacity, 0, energyStored);
|
||||
}
|
||||
|
||||
public ItemStack getAsItem() {
|
||||
ItemStack stack = new ItemStack(RSBlocks.PORTABLE_GRID, 1/* TODO, getPortableType() == PortableGridType.NORMAL ? ItemBlockPortableGrid.TYPE_NORMAL : ItemBlockPortableGrid.TYPE_CREATIVE*/);
|
||||
|
||||
public void applyDataFromTileToItem(ItemStack stack) {
|
||||
stack.setTag(new CompoundNBT());
|
||||
|
||||
stack.getTag().putInt(GridNetworkNode.NBT_SORTING_DIRECTION, sortingDirection);
|
||||
@@ -293,7 +279,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
stack.getTag().put(NBT_ENCHANTMENTS, enchants);
|
||||
}
|
||||
|
||||
stack.getCapability(CapabilityEnergy.ENERGY, null).ifPresent(energyStorage -> energyStorage.receiveEnergy(energyStorage.getEnergyStored(), false));
|
||||
stack.getCapability(CapabilityEnergy.ENERGY, null).ifPresent(itemEnergy -> itemEnergy.receiveEnergy(energyStorage.getEnergyStored(), false));
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
StackUtils.writeItems(filter, i, stack.getTag());
|
||||
@@ -302,8 +288,15 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
StackUtils.writeItems(disk, 4, stack.getTag());
|
||||
|
||||
redstoneMode.write(stack.getTag());
|
||||
}
|
||||
|
||||
return stack;
|
||||
private EnergyStorage createEnergyStorage(int energyStored) {
|
||||
return new EnergyStorage(
|
||||
RS.SERVER_CONFIG.getPortableGrid().getCapacity(),
|
||||
RS.SERVER_CONFIG.getPortableGrid().getCapacity(),
|
||||
RS.SERVER_CONFIG.getPortableGrid().getCapacity(),
|
||||
energyStored
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -450,7 +443,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
@Override
|
||||
public void onTabPageChanged(int page) {
|
||||
if (page >= 0 && page <= getTotalTabPages()) {
|
||||
TileDataManager.setParameter(TilePortableGrid.TAB_PAGE, page);
|
||||
TileDataManager.setParameter(PortableGridTile.TAB_PAGE, page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,19 +512,25 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
// NO OP
|
||||
}
|
||||
|
||||
private boolean hasDisk() {
|
||||
return !disk.getStackInSlot(0).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
int stored = !world.isRemote ? energyStorage.getEnergyStored() : ENERGY_STORED.getValue();
|
||||
if (world.isRemote) {
|
||||
return world.getBlockState(pos).get(PortableGridBlock.ACTIVE);
|
||||
}
|
||||
|
||||
/* TODO if (getPortableType() != PortableGridType.CREATIVE && RS.INSTANCE.config.portableGridUsesEnergy && stored <= RS.INSTANCE.config.portableGridOpenUsage) {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
if (disk.getStackInSlot(0).isEmpty()) {
|
||||
if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() &&
|
||||
type != PortableGridBlockItem.Type.CREATIVE &&
|
||||
energyStorage.getEnergyStored() <= RS.SERVER_CONFIG.getPortableGrid().getOpenUsage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RedstoneMode redstoneMode = !world.isRemote ? this.redstoneMode : RedstoneMode.getById(REDSTONE_MODE.getValue());
|
||||
if (!hasDisk()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return redstoneMode.isEnabled(world, pos);
|
||||
}
|
||||
@@ -550,56 +549,61 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
|
||||
@Override
|
||||
public void drainEnergy(int energy) {
|
||||
/* TODO if (RS.INSTANCE.config.portableGridUsesEnergy && getPortableType() != PortableGridType.CREATIVE && redstoneMode.isEnabled(world, pos)) {
|
||||
if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() &&
|
||||
type != PortableGridBlockItem.Type.CREATIVE &&
|
||||
redstoneMode.isEnabled(world, pos)) {
|
||||
energyStorage.extractEnergy(energy, false);
|
||||
|
||||
checkIfDiskStateChanged();
|
||||
}*/
|
||||
|
||||
checkIfConnectivityChanged();
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public int getStored() {
|
||||
return storage != null ? storage.getStored() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return storage != null ? storage.getCapacity() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStorage() {
|
||||
return storage != null;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public int getEnergy() {
|
||||
/* TODO if (RS.INSTANCE.config.portableGridUsesEnergy && getPortableType() != PortableGridType.CREATIVE) {
|
||||
if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() && type != PortableGridBlockItem.Type.CREATIVE) {
|
||||
return energyStorage.getEnergyStored();
|
||||
}*/
|
||||
}
|
||||
|
||||
return energyStorage.getEnergyStored();
|
||||
return RS.SERVER_CONFIG.getPortableGrid().getCapacity();
|
||||
}
|
||||
|
||||
private void checkIfDiskStateChanged() {
|
||||
@Override
|
||||
public PortableGridDiskState getDiskState() {
|
||||
if (!hasDisk()) {
|
||||
return PortableGridDiskState.NONE;
|
||||
}
|
||||
|
||||
if (!isActive()) {
|
||||
return PortableGridDiskState.DISCONNECTED;
|
||||
}
|
||||
|
||||
int stored = storage != null ? storage.getStored() : 0;
|
||||
int capacity = storage != null ? storage.getCapacity() : 0;
|
||||
|
||||
if (stored == capacity) {
|
||||
return PortableGridDiskState.FULL;
|
||||
} else if ((int) ((float) stored / (float) capacity * 100F) >= DiskState.DISK_NEAR_CAPACITY_THRESHOLD) {
|
||||
return PortableGridDiskState.NEAR_CAPACITY;
|
||||
} else {
|
||||
return PortableGridDiskState.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
PortableGridDiskState newDiskState = getDiskState();
|
||||
|
||||
if (this.diskState != newDiskState) {
|
||||
this.diskState = newDiskState;
|
||||
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(PortableGridBlock.DISK_STATE, diskState));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfConnectivityChanged() {
|
||||
boolean isConnected = getEnergy() != 0;
|
||||
boolean isActive = isActive();
|
||||
|
||||
if (this.connected != isConnected) {
|
||||
this.connected = isConnected;
|
||||
if (this.active != isActive) {
|
||||
this.active = isActive;
|
||||
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(PortableGridBlock.ACTIVE, active));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,7 +672,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
StackUtils.readItems(filter, 1, tag);
|
||||
|
||||
if (tag.contains(NBT_ENERGY)) {
|
||||
energyStorage = recreateEnergyStorage(tag.getInt(NBT_ENERGY));
|
||||
energyStorage = createEnergyStorage(tag.getInt(NBT_ENERGY));
|
||||
}
|
||||
|
||||
redstoneMode = RedstoneMode.read(tag);
|
||||
@@ -686,20 +690,8 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
this.loadStorage();
|
||||
|
||||
this.connected = getEnergy() != 0;
|
||||
this.diskState = getDiskState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT writeUpdate(CompoundNBT tag) {
|
||||
tag.putInt(NBT_DISK_STATE, diskState.getId());
|
||||
tag.putBoolean(NBT_CONNECTED, getEnergy() != 0);
|
||||
tag.putInt(NBT_TYPE, getServerGridType().ordinal());
|
||||
|
||||
return super.writeUpdate(tag);
|
||||
@@ -709,8 +701,6 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
public void readUpdate(CompoundNBT tag) {
|
||||
super.readUpdate(tag);
|
||||
|
||||
diskState = PortableGridDiskState.getById(tag.getInt(NBT_DISK_STATE));
|
||||
connected = tag.getBoolean(NBT_CONNECTED);
|
||||
clientGridType = GridType.values()[tag.getInt(NBT_TYPE)];
|
||||
}
|
||||
|
||||
@@ -725,7 +715,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
}
|
||||
|
||||
public void onOpened() {
|
||||
// TODO drainEnergy(RS.INSTANCE.config.portableGridOpenUsage);
|
||||
drainEnergy(RS.SERVER_CONFIG.getPortableGrid().getOpenUsage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -740,25 +730,6 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortableGridDiskState getDiskState() {
|
||||
//if (!renderInfo.hasStorage()) {
|
||||
return PortableGridDiskState.NONE;
|
||||
/*}
|
||||
|
||||
if (!renderInfo.isActive()) {
|
||||
return PortableGridDiskState.DISCONNECTED;
|
||||
}
|
||||
|
||||
if (renderInfo.getStored() == renderInfo.getCapacity()) {
|
||||
return PortableGridDiskState.FULL;
|
||||
} else if ((int) ((float) renderInfo.getStored() / (float) renderInfo.getCapacity() * 100F) >= DiskState.DISK_NEAR_CAPACITY_THRESHOLD) {
|
||||
return PortableGridDiskState.NEAR_CAPACITY;
|
||||
} else {
|
||||
return PortableGridDiskState.NORMAL;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return AccessType.INSERT_EXTRACT;
|
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "refinedstorage:block/portable_grid_disconnected"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,2 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "refinedstorage:block/portable_grid_disconnected"
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "refinedstorage:creative_portable_grid",
|
||||
"functions": [
|
||||
{
|
||||
"function": "refinedstorage:portable_grid"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "refinedstorage:portable_grid",
|
||||
"functions": [
|
||||
{
|
||||
"function": "refinedstorage:portable_grid"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user