Add disk manipulator model. Still needs to be more generic.

This commit is contained in:
Raoul Van den Berge
2016-10-29 14:44:52 +02:00
parent e2d3047ddb
commit c2524c5689
23 changed files with 574 additions and 180 deletions

View File

@@ -181,6 +181,10 @@ public abstract class FluidStorageNBT implements IFluidStorage {
return capacity; return capacity;
} }
public boolean isFull() {
return getStored() == getCapacity();
}
public NBTTagCompound getTag() { public NBTTagCompound getTag() {
return tag; return tag;
} }

View File

@@ -224,6 +224,10 @@ public abstract class ItemStorageNBT implements IItemStorage {
return capacity; return capacity;
} }
public boolean isFull() {
return getStored() == getCapacity();
}
public NBTTagCompound getTag() { public NBTTagCompound getTag() {
return tag; return tag;
} }

View File

@@ -2,7 +2,9 @@ package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui; import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.PropertyObject;
import com.raoulvdberge.refinedstorage.tile.TileDiskManipulator; import com.raoulvdberge.refinedstorage.tile.TileDiskManipulator;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -10,11 +12,15 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class BlockDiskManipulator extends BlockNode { public class BlockDiskManipulator extends BlockNode {
public static final PropertyObject<Integer[]> DISK_STATE = new PropertyObject<>("disk_state", Integer[].class);
public BlockDiskManipulator() { public BlockDiskManipulator() {
super("disk_manipulator"); super("disk_manipulator");
} }
@@ -33,6 +39,16 @@ public class BlockDiskManipulator extends BlockNode {
return true; return true;
} }
@Override
protected BlockStateContainer.Builder createBlockStateBuilder() {
return super.createBlockStateBuilder().add(DISK_STATE);
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(DISK_STATE, ((TileDiskManipulator) world.getTileEntity(pos)).getDiskState());
}
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { public void breakBlock(World world, BlockPos pos, IBlockState state) {
((TileDiskManipulator) world.getTileEntity(pos)).onBreak(); ((TileDiskManipulator) world.getTileEntity(pos)).onBreak();

View File

@@ -14,7 +14,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class BlockNode extends BlockBase { public abstract class BlockNode extends BlockBase {
private static final PropertyBool CONNECTED = PropertyBool.create("connected"); public static final PropertyBool CONNECTED = PropertyBool.create("connected");
public BlockNode(String name) { public BlockNode(String name) {
super(name); super(name);

View File

@@ -15,12 +15,12 @@ public class ContainerDiskManipulator extends ContainerBase {
addSlotToContainer(new SlotItemHandler(manipulator.getUpgrades(), i, 187, 6 + (i * 18))); addSlotToContainer(new SlotItemHandler(manipulator.getUpgrades(), i, 187, 6 + (i * 18)));
} }
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 3; ++i) {
addSlotToContainer(new SlotItemHandler(manipulator.getInputDisks(), i, 26 + (i % 2 * 18), ((i / 2) * 18) + 57)); addSlotToContainer(new SlotItemHandler(manipulator.getInputDisks(), i, 44, 57 + (i * 18)));
} }
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 3; ++i) {
addSlotToContainer(new SlotItemHandler(manipulator.getOutputDisks(), i, 116 + (i % 2 * 18), ((i / 2) * 18) + 57)); addSlotToContainer(new SlotItemHandler(manipulator.getOutputDisks(), i, 116, 57 + (i * 18)));
} }
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
@@ -39,12 +39,12 @@ public class ContainerDiskManipulator extends ContainerBase {
if (slot != null && slot.getHasStack()) { if (slot != null && slot.getHasStack()) {
stack = slot.getStack(); stack = slot.getStack();
if (index < 4 + 12) { if (index < 4 + 6) {
if (!mergeItemStack(stack, 4 + 12 + 9, inventorySlots.size(), false)) { if (!mergeItemStack(stack, 4 + 6 + 9, inventorySlots.size(), false)) {
return null; return null;
} }
} else if (!mergeItemStack(stack, 0, 16, false)) { } else if (!mergeItemStack(stack, 0, 16, false)) {
return mergeItemStackToSpecimen(stack, 4 + 12, 4 + 12 + 9); return mergeItemStackToSpecimen(stack, 4 + 6, 4 + 6 + 9);
} }
if (stack.stackSize == 0) { if (stack.stackSize == 0) {

View File

@@ -10,6 +10,7 @@ import com.raoulvdberge.refinedstorage.item.*;
import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse; import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse;
import com.raoulvdberge.refinedstorage.render.BakedModelPattern; import com.raoulvdberge.refinedstorage.render.BakedModelPattern;
import com.raoulvdberge.refinedstorage.render.ModelDiskDrive; import com.raoulvdberge.refinedstorage.render.ModelDiskDrive;
import com.raoulvdberge.refinedstorage.render.ModelDiskManipulator;
import com.raoulvdberge.refinedstorage.tile.TileController; import com.raoulvdberge.refinedstorage.tile.TileController;
import mcmultipart.client.multipart.ModelMultipartContainer; import mcmultipart.client.multipart.ModelMultipartContainer;
import mcmultipart.raytrace.PartMOP; import mcmultipart.raytrace.PartMOP;
@@ -215,6 +216,22 @@ public class ProxyClient extends ProxyCommon {
} }
}); });
ModelLoaderRegistry.registerLoader(new ICustomModelLoader() {
@Override
public boolean accepts(ResourceLocation modelLocation) {
return modelLocation.getResourceDomain().equals(RS.ID) && modelLocation.getResourcePath().equals("disk_manipulator");
}
@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
return new ModelDiskManipulator();
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
}
});
ModelLoader.setCustomStateMapper(RSBlocks.CONTROLLER, new StateMap.Builder().ignore(BlockController.TYPE).build()); ModelLoader.setCustomStateMapper(RSBlocks.CONTROLLER, new StateMap.Builder().ignore(BlockController.TYPE).build());
ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(RSBlocks.CONTROLLER), stack -> { ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(RSBlocks.CONTROLLER), stack -> {

View File

@@ -111,12 +111,12 @@ public class BakedModelDiskDrive implements IBakedModel {
Vector3f trans = model.transformation.getTranslation(); Vector3f trans = model.transformation.getTranslation();
if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH) { if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH) {
trans.x += (((float) x * 7F) / 16F) * (facing == EnumFacing.NORTH ? -1 : 1); trans.x += ((2F / 16F) + ((float) x * 7F) / 16F) * (facing == EnumFacing.NORTH ? -1 : 1);
} else if (facing == EnumFacing.EAST || facing == EnumFacing.WEST) { } else if (facing == EnumFacing.EAST || facing == EnumFacing.WEST) {
trans.z += (((float) x * 7F) / 16F) * (facing == EnumFacing.EAST ? -1 : 1); trans.z += ((2F / 16F) + ((float) x * 7F) / 16F) * (facing == EnumFacing.EAST ? -1 : 1);
} }
trans.y -= ((float) y * 3F) / 16F; trans.y -= (2F / 16F) + ((float) y * 3F) / 16F;
model.transformation = new TRSRTransformation(trans, model.transformation.getLeftRot(), model.transformation.getScale(), model.transformation.getRightRot()); model.transformation = new TRSRTransformation(trans, model.transformation.getLeftRot(), model.transformation.getScale(), model.transformation.getRightRot());

View File

@@ -0,0 +1,178 @@
package com.raoulvdberge.refinedstorage.render;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.raoulvdberge.refinedstorage.block.BlockBase;
import com.raoulvdberge.refinedstorage.block.BlockDiskManipulator;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.common.property.IExtendedBlockState;
import javax.annotation.Nullable;
import javax.vecmath.Vector3f;
import java.util.*;
public class BakedModelDiskManipulator implements IBakedModel {
private class CacheKey {
private IBlockState state;
private EnumFacing side;
private Integer[] diskState;
CacheKey(IBlockState state, @Nullable EnumFacing side, Integer[] diskState) {
this.state = state;
this.side = side;
this.diskState = diskState;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CacheKey cacheKey = (CacheKey) o;
if (!state.equals(cacheKey.state)) {
return false;
}
if (side != cacheKey.side) {
return false;
}
return Arrays.equals(diskState, cacheKey.diskState);
}
@Override
public int hashCode() {
int result = state.hashCode();
result = 31 * result + (side != null ? side.hashCode() : 0);
result = 31 * result + Arrays.hashCode(diskState);
return result;
}
}
private IBakedModel baseConnected;
private IBakedModel baseDisconnected;
private Map<EnumFacing, IBakedModel> modelsConnected = new HashMap<>();
private Map<EnumFacing, IBakedModel> modelsDisconnected = new HashMap<>();
private Map<EnumFacing, Map<Integer, List<IBakedModel>>> disks = new HashMap<>();
private LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
@Override
public List<BakedQuad> load(CacheKey key) throws Exception {
EnumFacing facing = key.state.getValue(BlockBase.DIRECTION);
List<BakedQuad> quads = (key.state.getValue(BlockDiskManipulator.CONNECTED) ? modelsConnected : modelsDisconnected).get(facing).getQuads(key.state, key.side, 0);
for (int i = 0; i < 6; ++i) {
if (key.diskState[i] != TileDiskDrive.DISK_STATE_NONE) {
quads.addAll(disks.get(facing).get(key.diskState[i]).get(i).getQuads(key.state, key.side, 0));
}
}
return quads;
}
});
public BakedModelDiskManipulator(IBakedModel baseConnected, IBakedModel baseDisconnected, IBakedModel disk, IBakedModel diskFull, IBakedModel diskDisconnected) {
this.baseConnected = baseConnected;
this.baseDisconnected = baseDisconnected;
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
modelsConnected.put(facing, new BakedModelTRSR(baseConnected, facing));
modelsDisconnected.put(facing, new BakedModelTRSR(baseDisconnected, facing));
disks.put(facing, new HashMap<>());
disks.get(facing).put(TileDiskDrive.DISK_STATE_NORMAL, new ArrayList<>());
disks.get(facing).put(TileDiskDrive.DISK_STATE_FULL, new ArrayList<>());
disks.get(facing).put(TileDiskDrive.DISK_STATE_DISCONNECTED, new ArrayList<>());
initDiskModels(disk, TileDiskDrive.DISK_STATE_NORMAL, facing);
initDiskModels(diskFull, TileDiskDrive.DISK_STATE_FULL, facing);
initDiskModels(diskDisconnected, TileDiskDrive.DISK_STATE_DISCONNECTED, facing);
}
}
private void initDiskModels(IBakedModel disk, int type, EnumFacing facing) {
for (int x = 0; x < 2; ++x) {
for (int y = 0; y < 3; ++y) {
BakedModelTRSR model = new BakedModelTRSR(disk, facing);
Vector3f trans = model.transformation.getTranslation();
if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH) {
trans.x += (2F / 16F + ((float) x * 7F) / 16F) * (facing == EnumFacing.NORTH ? -1 : 1);
} else if (facing == EnumFacing.EAST || facing == EnumFacing.WEST) {
trans.z += (2F / 16F + ((float) x * 7F) / 16F) * (facing == EnumFacing.EAST ? -1 : 1);
}
trans.y -= (6F / 16F) + (3F * y) / 16F;
model.transformation = new TRSRTransformation(trans, model.transformation.getLeftRot(), model.transformation.getScale(), model.transformation.getRightRot());
disks.get(facing).get(type).add(model);
}
}
}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (!(state instanceof IExtendedBlockState)) {
return baseDisconnected.getQuads(state, side, rand);
}
Integer[] diskState = ((IExtendedBlockState) state).getValue(BlockDiskManipulator.DISK_STATE);
if (diskState == null) {
return baseDisconnected.getQuads(state, side, rand);
}
CacheKey key = new CacheKey(((IExtendedBlockState) state).getClean(), side, diskState);
cache.refresh(key);
return cache.getUnchecked(key);
}
@Override
public boolean isAmbientOcclusion() {
return baseDisconnected.isAmbientOcclusion();
}
@Override
public boolean isGui3d() {
return baseDisconnected.isGui3d();
}
@Override
public boolean isBuiltInRenderer() {
return baseDisconnected.isBuiltInRenderer();
}
@Override
public TextureAtlasSprite getParticleTexture() {
return baseDisconnected.getParticleTexture();
}
@Override
public ItemCameraTransforms getItemCameraTransforms() {
return baseDisconnected.getItemCameraTransforms();
}
@Override
public ItemOverrideList getOverrides() {
return baseDisconnected.getOverrides();
}
}

View File

@@ -15,9 +15,9 @@ import java.util.Collections;
public class ModelDiskDrive implements IModel { public class ModelDiskDrive implements IModel {
private static final ResourceLocation MODEL_BASE = new ResourceLocation("refinedstorage:block/disk_drive"); private static final ResourceLocation MODEL_BASE = new ResourceLocation("refinedstorage:block/disk_drive");
private static final ResourceLocation MODEL_DISK = new ResourceLocation("refinedstorage:block/disk_drive_disk"); private static final ResourceLocation MODEL_DISK = new ResourceLocation("refinedstorage:block/disk");
private static final ResourceLocation MODEL_DISK_FULL = new ResourceLocation("refinedstorage:block/disk_drive_disk_full"); private static final ResourceLocation MODEL_DISK_FULL = new ResourceLocation("refinedstorage:block/disk_full");
private static final ResourceLocation MODEL_DISK_DISCONNECTED = new ResourceLocation("refinedstorage:block/disk_drive_disk_disconnected"); private static final ResourceLocation MODEL_DISK_DISCONNECTED = new ResourceLocation("refinedstorage:block/disk_disconnected");
@Override @Override
public Collection<ResourceLocation> getDependencies() { public Collection<ResourceLocation> getDependencies() {

View File

@@ -0,0 +1,64 @@
package com.raoulvdberge.refinedstorage.render;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import java.util.Collection;
import java.util.Collections;
public class ModelDiskManipulator implements IModel {
private static final ResourceLocation MODEL_BASE_CONNECTED = new ResourceLocation("refinedstorage:block/disk_manipulator_connected");
private static final ResourceLocation MODEL_BASE_DISCONNECTED = new ResourceLocation("refinedstorage:block/disk_manipulator_disconnected");
private static final ResourceLocation MODEL_DISK = new ResourceLocation("refinedstorage:block/disk");
private static final ResourceLocation MODEL_DISK_FULL = new ResourceLocation("refinedstorage:block/disk_full");
private static final ResourceLocation MODEL_DISK_DISCONNECTED = new ResourceLocation("refinedstorage:block/disk_disconnected");
@Override
public Collection<ResourceLocation> getDependencies() {
return Lists.newArrayList(MODEL_BASE_CONNECTED, MODEL_BASE_DISCONNECTED);
}
@Override
public Collection<ResourceLocation> getTextures() {
return Collections.emptyList();
}
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
IModel baseModelConnected, baseModelDisconnected;
IModel diskModel;
IModel diskModelFull;
IModel diskModelDisconnected;
try {
baseModelConnected = ModelLoaderRegistry.getModel(MODEL_BASE_CONNECTED);
baseModelDisconnected = ModelLoaderRegistry.getModel(MODEL_BASE_DISCONNECTED);
diskModel = ModelLoaderRegistry.getModel(MODEL_DISK);
diskModelFull = ModelLoaderRegistry.getModel(MODEL_DISK_FULL);
diskModelDisconnected = ModelLoaderRegistry.getModel(MODEL_DISK_DISCONNECTED);
} catch (Exception e) {
throw new Error("Unable to load disk manipulator models", e);
}
return new BakedModelDiskManipulator(
baseModelConnected.bake(state, format, bakedTextureGetter),
baseModelDisconnected.bake(state, format, bakedTextureGetter),
diskModel.bake(state, format, bakedTextureGetter),
diskModelFull.bake(state, format, bakedTextureGetter),
diskModelDisconnected.bake(state, format, bakedTextureGetter)
);
}
@Override
public IModelState getDefaultState() {
return TRSRTransformation.identity();
}
}

View File

@@ -85,10 +85,6 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
updateBlock(); updateBlock();
} }
} }
public boolean isFull() {
return getStored() == getCapacity();
}
} }
public class FluidStorage extends FluidStorageNBT { public class FluidStorage extends FluidStorageNBT {
@@ -136,10 +132,6 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
updateBlock(); updateBlock();
} }
} }
public boolean isFull() {
return getStored() == getCapacity();
}
} }
private static final String NBT_PRIORITY = "Priority"; private static final String NBT_PRIORITY = "Priority";
@@ -210,9 +202,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
dataManager.addWatchedParameter(VOID_EXCESS); dataManager.addWatchedParameter(VOID_EXCESS);
dataManager.addWatchedParameter(ACCESS_TYPE); dataManager.addWatchedParameter(ACCESS_TYPE);
for (int i = 0; i < 8; ++i) { initDiskState(diskState);
diskState[i] = DISK_STATE_NONE;
}
} }
@Override @Override
@@ -338,7 +328,24 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
public NBTTagCompound writeUpdate(NBTTagCompound tag) { public NBTTagCompound writeUpdate(NBTTagCompound tag) {
super.writeUpdate(tag); super.writeUpdate(tag);
for (int i = 0; i < 8; ++i) { writeDiskState(tag, 8, connected, itemStorages, fluidStorages);
return tag;
}
@Override
public void readUpdate(NBTTagCompound tag) {
super.readUpdate(tag);
readDiskState(tag, diskState);
}
public Integer[] getDiskState() {
return diskState;
}
public static void writeDiskState(NBTTagCompound tag, int disks, boolean connected, ItemStorageNBT[] itemStorages, FluidStorageNBT[] fluidStorages) {
for (int i = 0; i < disks; ++i) {
int state = DISK_STATE_NONE; int state = DISK_STATE_NONE;
if (itemStorages[i] != null || fluidStorages[i] != null) { if (itemStorages[i] != null || fluidStorages[i] != null) {
@@ -355,21 +362,18 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
tag.setInteger(String.format(NBT_DISK_STATE, i), state); tag.setInteger(String.format(NBT_DISK_STATE, i), state);
} }
return tag;
} }
@Override public static void readDiskState(NBTTagCompound tag, Integer[] diskState) {
public void readUpdate(NBTTagCompound tag) { for (int i = 0; i < diskState.length; ++i) {
super.readUpdate(tag);
for (int i = 0; i < 8; ++i) {
diskState[i] = tag.getInteger(String.format(NBT_DISK_STATE, i)); diskState[i] = tag.getInteger(String.format(NBT_DISK_STATE, i));
} }
} }
public Integer[] getDiskState() { public static void initDiskState(Integer[] diskState) {
return diskState; for (int i = 0; i < diskState.length; ++i) {
diskState[i] = DISK_STATE_NONE;
}
} }
@Override @Override

View File

@@ -67,22 +67,19 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
private ItemStorage[] itemStorages = new ItemStorage[6]; private ItemStorage[] itemStorages = new ItemStorage[6];
private FluidStorage[] fluidStorages = new FluidStorage[6]; private FluidStorage[] fluidStorages = new FluidStorage[6];
public TileDiskManipulator() { private Integer[] diskState = new Integer[6];
dataManager.addWatchedParameter(COMPARE);
dataManager.addWatchedParameter(MODE);
dataManager.addWatchedParameter(TYPE);
dataManager.addWatchedParameter(IO_MODE);
}
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, this, ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK); private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, this, ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK);
private ItemHandlerBasic inputDisks = new ItemHandlerBasic(6, this, IItemValidator.STORAGE_DISK) { private ItemHandlerBasic inputDisks = new ItemHandlerBasic(3, this, IItemValidator.STORAGE_DISK) {
@Override @Override
protected void onContentsChanged(int slot) { protected void onContentsChanged(int slot) {
super.onContentsChanged(slot); super.onContentsChanged(slot);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
RSUtils.constructFromDrive(getStackInSlot(slot), slot, itemStorages, fluidStorages, ItemStorage::new, FluidStorage::new); RSUtils.constructFromDrive(getStackInSlot(slot), slot, itemStorages, fluidStorages, ItemStorage::new, FluidStorage::new);
updateBlock();
} }
} }
@@ -100,11 +97,26 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
} }
}; };
private ItemHandlerBasic outputDisks = new ItemHandlerBasic(6, this, IItemValidator.STORAGE_DISK); private ItemHandlerBasic outputDisks = new ItemHandlerBasic(3, this, IItemValidator.STORAGE_DISK) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
RSUtils.constructFromDrive(getStackInSlot(slot), 3 + slot, itemStorages, fluidStorages, ItemStorage::new, FluidStorage::new);
updateBlock();
}
}
};
public class ItemStorage extends ItemStorageNBT { public class ItemStorage extends ItemStorageNBT {
private boolean wasFull;
public ItemStorage(ItemStack disk) { public ItemStorage(ItemStack disk) {
super(disk.getTagCompound(), EnumItemStorageType.getById(disk.getItemDamage()).getCapacity(), TileDiskManipulator.this); super(disk.getTagCompound(), EnumItemStorageType.getById(disk.getItemDamage()).getCapacity(), TileDiskManipulator.this);
wasFull = isFull();
} }
@Override @Override
@@ -129,11 +141,26 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
return super.extractItem(stack, size, flags); return super.extractItem(stack, size, flags);
} }
@Override
public void onStorageChanged() {
super.onStorageChanged();
if (wasFull != isFull()) {
wasFull = isFull();
updateBlock();
}
}
} }
public class FluidStorage extends FluidStorageNBT { public class FluidStorage extends FluidStorageNBT {
private boolean wasFull;
public FluidStorage(ItemStack disk) { public FluidStorage(ItemStack disk) {
super(disk.getTagCompound(), EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity(), TileDiskManipulator.this); super(disk.getTagCompound(), EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity(), TileDiskManipulator.this);
wasFull = isFull();
} }
@Override @Override
@@ -158,11 +185,31 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
return super.extractFluid(stack, size, flags); return super.extractFluid(stack, size, flags);
} }
@Override
public void onStorageChanged() {
super.onStorageChanged();
if (wasFull != isFull()) {
wasFull = isFull();
updateBlock();
}
}
} }
private ItemHandlerBasic itemFilters = new ItemHandlerBasic(9, this); private ItemHandlerBasic itemFilters = new ItemHandlerBasic(9, this);
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, this); private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, this);
public TileDiskManipulator() {
dataManager.addWatchedParameter(COMPARE);
dataManager.addWatchedParameter(MODE);
dataManager.addWatchedParameter(TYPE);
dataManager.addWatchedParameter(IO_MODE);
TileDiskDrive.initDiskState(diskState);
}
@Override @Override
public int getEnergyUsage() { public int getEnergyUsage() {
return RS.INSTANCE.config.diskManipulatorUsage + upgrades.getEnergyUsage(); return RS.INSTANCE.config.diskManipulatorUsage + upgrades.getEnergyUsage();
@@ -180,11 +227,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
} }
int slot = 0; int slot = 0;
if (type == IType.ITEMS) { if (type == IType.ITEMS) {
while (slot < itemStorages.length && itemStorages[slot] == null) { while (slot < 3 && itemStorages[slot] == null) {
slot++; slot++;
} }
if (slot == itemStorages.length) { if (slot == 3) {
return; return;
} }
@@ -196,11 +243,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
extractFromNetwork(storage, slot); extractFromNetwork(storage, slot);
} }
} else if (type == IType.FLUIDS) { } else if (type == IType.FLUIDS) {
while (slot < fluidStorages.length && fluidStorages[slot] == null) { while (slot < 3 && fluidStorages[slot] == null) {
slot++; slot++;
} }
if (slot == fluidStorages.length) { if (slot == 3) {
return; return;
} }
@@ -378,15 +425,15 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
ItemStack disk = inputDisks.getStackInSlot(slot); ItemStack disk = inputDisks.getStackInSlot(slot);
if (disk != null) { if (disk != null) {
int i = 0; int i = 0;
while (i < 6 && outputDisks.getStackInSlot(i) != null) { while (i < 3 && outputDisks.getStackInSlot(i) != null) {
i++; i++;
} }
if (i == 6) { if (i == 3) {
return; return;
} }
if (slot < 6) { if (slot < 3) {
if (itemStorages[slot] != null) { if (itemStorages[slot] != null) {
itemStorages[slot].writeToNBT(); itemStorages[slot].writeToNBT();
itemStorages[slot] = null; itemStorages[slot] = null;
@@ -453,24 +500,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
public void read(NBTTagCompound tag) { public void read(NBTTagCompound tag) {
super.read(tag); super.read(tag);
// Backwards Compatibility
ItemHandlerBasic oldDisks = new ItemHandlerBasic(12, this, IItemValidator.STORAGE_DISK);
RSUtils.readItems(oldDisks, 0, tag);
for (int i = 0; i < 12; ++i) {
ItemStack stack = oldDisks.extractItem(i, 1, false);
if (stack != null) {
if (i < 6) {
inputDisks.insertItem(i, stack, false);
} else {
outputDisks.insertItem(i, stack, false);
}
}
}
RSUtils.readItems(itemFilters, 1, tag); RSUtils.readItems(itemFilters, 1, tag);
RSUtils.readItems(fluidFilters, 2, tag); RSUtils.readItems(fluidFilters, 2, tag);
RSUtils.readItems(upgrades, 3, tag); RSUtils.readItems(upgrades, 3, tag);
RSUtils.readItems(outputDisks, 4, tag); RSUtils.readItems(inputDisks, 4, tag);
RSUtils.readItems(outputDisks, 5, tag);
if (tag.hasKey(NBT_COMPARE)) { if (tag.hasKey(NBT_COMPARE)) {
compare = tag.getInteger(NBT_COMPARE); compare = tag.getInteger(NBT_COMPARE);
@@ -495,11 +529,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
onBreak(); onBreak();
RSUtils.writeItems(inputDisks, 0, tag);
RSUtils.writeItems(itemFilters, 1, tag); RSUtils.writeItems(itemFilters, 1, tag);
RSUtils.writeItems(fluidFilters, 2, tag); RSUtils.writeItems(fluidFilters, 2, tag);
RSUtils.writeItems(upgrades, 3, tag); RSUtils.writeItems(upgrades, 3, tag);
RSUtils.writeItems(outputDisks, 4, tag); RSUtils.writeItems(inputDisks, 4, tag);
RSUtils.writeItems(outputDisks, 5, tag);
tag.setInteger(NBT_COMPARE, compare); tag.setInteger(NBT_COMPARE, compare);
tag.setInteger(NBT_MODE, mode); tag.setInteger(NBT_MODE, mode);
@@ -509,6 +543,26 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
return tag; return tag;
} }
@Override
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
super.writeUpdate(tag);
TileDiskDrive.writeDiskState(tag, 6, connected, itemStorages, fluidStorages);
return tag;
}
@Override
public void readUpdate(NBTTagCompound tag) {
super.readUpdate(tag);
TileDiskDrive.readDiskState(tag, diskState);
}
public Integer[] getDiskState() {
return diskState;
}
@Override @Override
public IItemHandler getDrops() { public IItemHandler getDrops() {
return new CombinedInvWrapper(inputDisks, outputDisks, upgrades); return new CombinedInvWrapper(inputDisks, outputDisks, upgrades);

View File

@@ -1,47 +0,0 @@
{
"forge_marker": 1,
"defaults": {
"model": "orientable",
"textures": {
"side": "refinedstorage:blocks/side",
"top": "refinedstorage:blocks/side",
"front": "refinedstorage:blocks/disk_manipulator_disconnected"
}
},
"variants": {
"inventory": [
{
"y": 0
}
],
"connected": {
"true": {
"textures": {
"front": "refinedstorage:blocks/disk_manipulator_connected"
}
},
"false": {
}
},
"direction": {
"north": {
"y": 0
},
"east": {
"y": 90
},
"south": {
"y": 180
},
"west": {
"y": 270
},
"up": {
"x": 270
},
"down": {
"x": 90
}
}
}
}

View File

@@ -1,24 +1,24 @@
{ {
"__comment": "Model made by CyanideX", "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)",
"textures": { "textures": {
"disk": "refinedstorage:blocks/disk_drive_disk_full" "0": "refinedstorage:blocks/disk"
}, },
"elements": [ "elements": [
{ {
"name": "disk", "name": "disk",
"from": [ "from": [
9.0, 11.0,
12.0, 14.0,
-1.0 -1.0
], ],
"to": [ "to": [
14.0, 16.0,
14.0, 16.0,
0.0 0.0
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
0.0, 0.0,
@@ -27,7 +27,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
2.0, 2.0,
0.0, 0.0,
@@ -36,7 +36,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
9.0, 9.0,
0.0, 0.0,
@@ -45,7 +45,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
8.0, 8.0,
0.0, 0.0,
@@ -54,7 +54,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
2.0, 2.0,
@@ -63,7 +63,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
3.0, 3.0,
@@ -76,18 +76,18 @@
{ {
"name": "led", "name": "led",
"from": [ "from": [
10.0, 12.0,
11.95, 13.95,
-1.05 -1.05
], ],
"to": [ "to": [
11.0,
13.0, 13.0,
15.0,
-0.10000000000000009 -0.10000000000000009
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -96,7 +96,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -105,7 +105,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -114,7 +114,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -123,7 +123,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -132,7 +132,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,

View File

@@ -1,24 +1,24 @@
{ {
"__comment": "Model made by CyanideX", "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)",
"textures": { "textures": {
"disk": "refinedstorage:blocks/disk_drive_disk_disconnected" "0": "refinedstorage:blocks/disk_disconnected"
}, },
"elements": [ "elements": [
{ {
"name": "disk", "name": "disk",
"from": [ "from": [
9.0, 11.0,
12.0, 14.0,
-1.0 -1.0
], ],
"to": [ "to": [
14.0, 16.0,
14.0, 16.0,
0.0 0.0
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
0.0, 0.0,
@@ -27,7 +27,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
2.0, 2.0,
0.0, 0.0,
@@ -36,7 +36,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
9.0, 9.0,
0.0, 0.0,
@@ -45,7 +45,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
8.0, 8.0,
0.0, 0.0,
@@ -54,7 +54,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
2.0, 2.0,
@@ -63,7 +63,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
3.0, 3.0,
@@ -76,18 +76,18 @@
{ {
"name": "led", "name": "led",
"from": [ "from": [
10.0, 12.0,
11.95, 13.95,
-1.05 -1.05
], ],
"to": [ "to": [
11.0,
13.0, 13.0,
15.0,
-0.10000000000000009 -0.10000000000000009
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -96,7 +96,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -105,7 +105,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -114,7 +114,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -123,7 +123,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -132,7 +132,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,

View File

@@ -1,24 +1,24 @@
{ {
"__comment": "Model made by CyanideX", "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)",
"textures": { "textures": {
"disk": "refinedstorage:blocks/disk_drive_disk" "0": "refinedstorage:blocks/disk_full"
}, },
"elements": [ "elements": [
{ {
"name": "disk", "name": "disk",
"from": [ "from": [
9.0, 11.0,
12.0, 14.0,
-1.0 -1.0
], ],
"to": [ "to": [
14.0, 16.0,
14.0, 16.0,
0.0 0.0
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
0.0, 0.0,
@@ -27,7 +27,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
2.0, 2.0,
0.0, 0.0,
@@ -36,7 +36,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
9.0, 9.0,
0.0, 0.0,
@@ -45,7 +45,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
8.0, 8.0,
0.0, 0.0,
@@ -54,7 +54,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
2.0, 2.0,
@@ -63,7 +63,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
3.0, 3.0,
3.0, 3.0,
@@ -76,18 +76,18 @@
{ {
"name": "led", "name": "led",
"from": [ "from": [
10.0, 12.0,
11.95, 13.95,
-1.05 -1.05
], ],
"to": [ "to": [
11.0,
13.0, 13.0,
15.0,
-0.10000000000000009 -0.10000000000000009
], ],
"faces": { "faces": {
"north": { "north": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -96,7 +96,7 @@
] ]
}, },
"east": { "east": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -105,7 +105,7 @@
] ]
}, },
"south": { "south": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -114,7 +114,7 @@
] ]
}, },
"west": { "west": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -123,7 +123,7 @@
] ]
}, },
"up": { "up": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,
@@ -132,7 +132,7 @@
] ]
}, },
"down": { "down": {
"texture": "#disk", "texture": "#0",
"uv": [ "uv": [
14.0, 14.0,
1.0, 1.0,

View File

@@ -0,0 +1,50 @@
{
"parent": "block/block",
"textures": {
"particle": "refinedstorage:blocks/disk_manipulator_connected",
"front": "refinedstorage:blocks/disk_manipulator_connected",
"bottom": "refinedstorage:blocks/side",
"top": "refinedstorage:blocks/side",
"side": "refinedstorage:blocks/side"
},
"elements": [
{
"from": [
0,
0,
0
],
"to": [
16,
16,
16
],
"faces": {
"down": {
"texture": "#bottom",
"cullface": "down"
},
"up": {
"texture": "#top",
"cullface": "up"
},
"north": {
"texture": "#front",
"cullface": "north"
},
"south": {
"texture": "#side",
"cullface": "south"
},
"west": {
"texture": "#side",
"cullface": "west"
},
"east": {
"texture": "#side",
"cullface": "east"
}
}
}
]
}

View File

@@ -0,0 +1,50 @@
{
"parent": "block/block",
"textures": {
"particle": "refinedstorage:blocks/disk_manipulator_disconnected",
"front": "refinedstorage:blocks/disk_manipulator_disconnected",
"bottom": "refinedstorage:blocks/side",
"top": "refinedstorage:blocks/side",
"side": "refinedstorage:blocks/side"
},
"elements": [
{
"from": [
0,
0,
0
],
"to": [
16,
16,
16
],
"faces": {
"down": {
"texture": "#bottom",
"cullface": "down"
},
"up": {
"texture": "#top",
"cullface": "up"
},
"north": {
"texture": "#front",
"cullface": "north"
},
"south": {
"texture": "#side",
"cullface": "south"
},
"west": {
"texture": "#side",
"cullface": "west"
},
"east": {
"texture": "#side",
"cullface": "east"
}
}
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB