Add disk drive disk textures

This commit is contained in:
Raoul Van den Berge
2016-10-23 03:42:41 +02:00
parent ca8a773e77
commit 8f044d5e72
8 changed files with 461 additions and 20 deletions

View File

@@ -2,7 +2,9 @@ package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.PropertyObject;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -10,9 +12,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
public class BlockDiskDrive extends BlockNode {
public static final PropertyObject<Integer[]> DISK_STATE = new PropertyObject<>("disk_state", Integer[].class);
public BlockDiskDrive() {
super("disk_drive");
}
@@ -31,6 +37,16 @@ public class BlockDiskDrive extends BlockNode {
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, ((TileDiskDrive) world.getTileEntity(pos)).getDiskState());
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
((TileDiskDrive) world.getTileEntity(pos)).onBreak();

View File

@@ -1,6 +1,8 @@
package com.raoulvdberge.refinedstorage.render;
import com.raoulvdberge.refinedstorage.block.BlockBase;
import com.raoulvdberge.refinedstorage.block.BlockDiskDrive;
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;
@@ -9,6 +11,7 @@ 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;
@@ -20,16 +23,27 @@ import java.util.Map;
public class BakedModelDiskDrive implements IBakedModel {
private IBakedModel base;
private Map<EnumFacing, IBakedModel> models = new HashMap<>();
private Map<EnumFacing, List<IBakedModel>> disks = new HashMap<>();
private Map<EnumFacing, Map<Integer, List<IBakedModel>>> disks = new HashMap<>();
public BakedModelDiskDrive(IBakedModel base, IBakedModel disk) {
public BakedModelDiskDrive(IBakedModel base, IBakedModel disk, IBakedModel diskFull, IBakedModel diskDisconnected) {
this.base = base;
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
models.put(facing, new BakedModelTRSR(base, facing));
disks.put(facing, new ArrayList<>());
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 y = 0; y < 4; ++y) {
for (int x = 0; x < 2; ++x) {
BakedModelTRSR model = new BakedModelTRSR(disk, facing);
@@ -46,24 +60,28 @@ public class BakedModelDiskDrive implements IBakedModel {
model.transformation = new TRSRTransformation(trans, model.transformation.getLeftRot(), model.transformation.getScale(), model.transformation.getRightRot());
disks.get(facing).add(model);
}
disks.get(facing).get(type).add(model);
}
}
}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (state == null) {
if (!(state instanceof IExtendedBlockState)) {
return base.getQuads(state, side, rand);
}
EnumFacing facing = state.getValue(BlockBase.DIRECTION);
Integer[] diskState = ((IExtendedBlockState) state).getValue(BlockDiskDrive.DISK_STATE);
List<BakedQuad> quads = models.get(facing).getQuads(state, side, rand);
if (diskState != null) {
for (int i = 0; i < 8; ++i) {
quads.addAll(disks.get(facing).get(i).getQuads(state, side, rand));
if (diskState[i] != null && diskState[i] != TileDiskDrive.DISK_STATE_NONE) {
quads.addAll(disks.get(facing).get(diskState[i]).get(i).getQuads(state, side, rand));
}
}
}
return quads;

View File

@@ -16,6 +16,8 @@ import java.util.Collections;
public class ModelDiskDrive implements IModel {
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_FULL = new ResourceLocation("refinedstorage:block/disk_drive_disk_full");
private static final ResourceLocation MODEL_DISK_DISCONNECTED = new ResourceLocation("refinedstorage:block/disk_drive_disk_disconnected");
@Override
public Collection<ResourceLocation> getDependencies() {
@@ -31,15 +33,24 @@ public class ModelDiskDrive implements IModel {
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
IModel baseModel;
IModel diskModel;
IModel diskModelFull;
IModel diskModelDisconnected;
try {
baseModel = ModelLoaderRegistry.getModel(MODEL_BASE);
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 drive models", e);
}
return new BakedModelDiskDrive(baseModel.bake(state, format, bakedTextureGetter), diskModel.bake(state, format, bakedTextureGetter));
return new BakedModelDiskDrive(
baseModel.bake(state, format, bakedTextureGetter),
diskModel.bake(state, format, bakedTextureGetter),
diskModelFull.bake(state, format, bakedTextureGetter),
diskModelDisconnected.bake(state, format, bakedTextureGetter)
);
}
@Override

View File

@@ -0,0 +1,52 @@
package com.raoulvdberge.refinedstorage.render;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.minecraftforge.common.property.IUnlistedProperty;
import java.util.Objects;
public class PropertyObject<T> implements IUnlistedProperty<T> {
private final String name;
private final Class<T> clazz;
private final Predicate<T> validator;
private final Function<T, String> stringFunction;
public PropertyObject(String name, Class<T> clazz, Predicate<T> validator, Function<T, String> stringFunction) {
this.name = name;
this.clazz = clazz;
this.validator = validator;
this.stringFunction = stringFunction;
}
public PropertyObject(String name, Class<T> clazz) {
this(name, clazz, Predicates.<T>alwaysTrue(), new Function<T, String>() {
@Override
public String apply(T input) {
return Objects.toString(input);
}
});
}
@Override
public String getName() {
return name;
}
@Override
public boolean isValid(T value) {
return validator.apply(value);
}
@Override
public Class<T> getType() {
return clazz;
}
@Override
public String valueToString(T value) {
return stringFunction.apply(value);
}
}

View File

@@ -109,6 +109,12 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
private static final String NBT_MODE = "Mode";
private static final String NBT_TYPE = "Type";
private static final String NBT_VOID_EXCESS = "VoidExcess";
private static final String NBT_DISK_STATE = "DiskState_%d";
public static final int DISK_STATE_NORMAL = 0;
public static final int DISK_STATE_FULL = 1;
public static final int DISK_STATE_DISCONNECTED = 2;
public static final int DISK_STATE_NONE = 3;
private ItemHandlerBasic disks = new ItemHandlerBasic(8, this, IItemValidator.STORAGE_DISK) {
@Override
@@ -156,6 +162,8 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
private int type = IType.ITEMS;
private boolean voidExcess = false;
private Integer[] diskState = new Integer[8];
public TileDiskDrive() {
dataManager.addWatchedParameter(PRIORITY);
dataManager.addWatchedParameter(COMPARE);
@@ -202,6 +210,8 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
network.getItemStorageCache().invalidate();
network.getFluidStorageCache().invalidate();
updateBlock();
}
@Override
@@ -282,6 +292,45 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
return tag;
}
@Override
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
super.writeUpdate(tag);
for (int i = 0; i < 8; ++i) {
int state = DISK_STATE_NONE;
if (itemStorages[i] != null || fluidStorages[i] != null) {
if (!connected) {
state = DISK_STATE_DISCONNECTED;
} else {
state = DISK_STATE_NORMAL;
if ((itemStorages[i] != null && itemStorages[i].getStored() == itemStorages[i].getCapacity()) ||
(fluidStorages[i] != null && fluidStorages[i].getStored() == fluidStorages[i].getCapacity())) {
state = DISK_STATE_FULL;
}
}
}
tag.setInteger(String.format(NBT_DISK_STATE, i), state);
}
return tag;
}
@Override
public void readUpdate(NBTTagCompound tag) {
super.readUpdate(tag);
for (int i = 0; i < 8; ++i) {
diskState[i] = tag.getInteger(String.format(NBT_DISK_STATE, i));
}
}
public Integer[] getDiskState() {
return diskState;
}
@Override
public int getCompare() {
return compare;

View File

@@ -1,5 +1,8 @@
{
"__comment": "Model made by CyanideX",
"textures": {
"disk": "refinedstorage:blocks/disk_drive_disk"
},
"elements": [
{
"name": "disk",

View File

@@ -0,0 +1,146 @@
{
"__comment": "Model made by CyanideX",
"textures": {
"disk": "refinedstorage:blocks/disk_drive_disk_disconnected"
},
"elements": [
{
"name": "disk",
"from": [
9.0,
12.0,
-1.0
],
"to": [
14.0,
14.0,
0.0
],
"faces": {
"north": {
"texture": "#disk",
"uv": [
3.0,
0.0,
8.0,
2.0
]
},
"east": {
"texture": "#disk",
"uv": [
2.0,
0.0,
3.0,
2.0
]
},
"south": {
"texture": "#disk",
"uv": [
9.0,
0.0,
14.0,
2.0
]
},
"west": {
"texture": "#disk",
"uv": [
8.0,
0.0,
9.0,
2.0
]
},
"up": {
"texture": "#disk",
"uv": [
3.0,
2.0,
8.0,
3.0
]
},
"down": {
"texture": "#disk",
"uv": [
3.0,
3.0,
8.0,
4.0
]
}
}
},
{
"name": "led",
"from": [
10.0,
11.95,
-1.05
],
"to": [
11.0,
13.0,
-0.10000000000000009
],
"faces": {
"north": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"east": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"south": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"west": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"up": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"down": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
}
}
}
]
}

View File

@@ -0,0 +1,146 @@
{
"__comment": "Model made by CyanideX",
"textures": {
"disk": "refinedstorage:blocks/disk_drive_disk_full"
},
"elements": [
{
"name": "disk",
"from": [
9.0,
12.0,
-1.0
],
"to": [
14.0,
14.0,
0.0
],
"faces": {
"north": {
"texture": "#disk",
"uv": [
3.0,
0.0,
8.0,
2.0
]
},
"east": {
"texture": "#disk",
"uv": [
2.0,
0.0,
3.0,
2.0
]
},
"south": {
"texture": "#disk",
"uv": [
9.0,
0.0,
14.0,
2.0
]
},
"west": {
"texture": "#disk",
"uv": [
8.0,
0.0,
9.0,
2.0
]
},
"up": {
"texture": "#disk",
"uv": [
3.0,
2.0,
8.0,
3.0
]
},
"down": {
"texture": "#disk",
"uv": [
3.0,
3.0,
8.0,
4.0
]
}
}
},
{
"name": "led",
"from": [
10.0,
11.95,
-1.05
],
"to": [
11.0,
13.0,
-0.10000000000000009
],
"faces": {
"north": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"east": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"south": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"west": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"up": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
},
"down": {
"texture": "#disk",
"uv": [
14.0,
1.0,
15.0,
2.0
]
}
}
}
]
}