Move DiskManipulatorBakedModel away from TRSRBakedModel
This commit is contained in:
@@ -134,17 +134,17 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Vector3f getDiskTranslation(Direction facing, int x, int y) {
|
private Vector3f getDiskTranslation(Direction facing, int x, int y) {
|
||||||
Vector3f trans = new Vector3f();
|
Vector3f translation = new Vector3f();
|
||||||
|
|
||||||
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
|
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
|
||||||
trans.add(((2F / 16F) + ((float) x * 7F) / 16F) * (facing == Direction.NORTH ? -1 : 1), 0, 0); // Add to X
|
translation.add(((2F / 16F) + ((float) x * 7F) / 16F) * (facing == Direction.NORTH ? -1 : 1), 0, 0); // Add to X
|
||||||
} else if (facing == Direction.EAST || facing == Direction.WEST) {
|
} else if (facing == Direction.EAST || facing == Direction.WEST) {
|
||||||
trans.add(0, 0, ((2F / 16F) + ((float) x * 7F) / 16F) * (facing == Direction.EAST ? -1 : 1)); // Add to Y
|
translation.add(0, 0, ((2F / 16F) + ((float) x * 7F) / 16F) * (facing == Direction.EAST ? -1 : 1)); // Add to Z
|
||||||
}
|
}
|
||||||
|
|
||||||
trans.add(0, -((2F / 16F) + ((float) y * 3F) / 16F), 0); // Remove from Y
|
translation.add(0, -((2F / 16F) + ((float) y * 3F) / 16F), 0); // Remove from Y
|
||||||
|
|
||||||
return trans;
|
return translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.refinedmods.refinedstorage.apiimpl.network.node.DiskState;
|
|||||||
import com.refinedmods.refinedstorage.block.DiskManipulatorBlock;
|
import com.refinedmods.refinedstorage.block.DiskManipulatorBlock;
|
||||||
import com.refinedmods.refinedstorage.tile.DiskManipulatorTile;
|
import com.refinedmods.refinedstorage.tile.DiskManipulatorTile;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.renderer.TransformationMatrix;
|
|
||||||
import net.minecraft.client.renderer.Vector3f;
|
import net.minecraft.client.renderer.Vector3f;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.model.IBakedModel;
|
||||||
@@ -17,7 +16,10 @@ import net.minecraftforge.client.model.data.IModelData;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class DiskManipulatorBakedModel extends DelegateBakedModel {
|
public class DiskManipulatorBakedModel extends DelegateBakedModel {
|
||||||
private static class CacheKey {
|
private static class CacheKey {
|
||||||
@@ -65,21 +67,48 @@ public class DiskManipulatorBakedModel extends DelegateBakedModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<Direction, IBakedModel> modelsConnected = new HashMap<>();
|
private final IBakedModel baseConnected;
|
||||||
private final Map<Direction, IBakedModel> modelsDisconnected = new HashMap<>();
|
private final IBakedModel baseDisconnected;
|
||||||
private final Map<Direction, Map<DiskState, List<IBakedModel>>> disks = new HashMap<>();
|
private final IBakedModel disk;
|
||||||
|
private final IBakedModel diskNearCapacity;
|
||||||
|
private final IBakedModel diskFull;
|
||||||
|
private final IBakedModel diskDisconnected;
|
||||||
|
|
||||||
private final LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
|
private final LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public List<BakedQuad> load(CacheKey key) {
|
public List<BakedQuad> load(CacheKey key) {
|
||||||
Direction facing = key.state.get(RSBlocks.DISK_MANIPULATOR.getDirection().getProperty());
|
Direction facing = key.state.get(RSBlocks.DISK_MANIPULATOR.getDirection().getProperty());
|
||||||
|
boolean connected = key.state.get(DiskManipulatorBlock.CONNECTED);
|
||||||
|
|
||||||
List<BakedQuad> quads = new ArrayList<>((key.state.get(DiskManipulatorBlock.CONNECTED) ? modelsConnected : modelsDisconnected).get(facing).getQuads(key.state, key.side, key.random));
|
List<BakedQuad> quads = new ArrayList<>(QuadTransformer.getTransformedQuads(
|
||||||
|
connected ? baseConnected : baseDisconnected,
|
||||||
|
facing,
|
||||||
|
null,
|
||||||
|
key.state,
|
||||||
|
key.random,
|
||||||
|
key.side
|
||||||
|
));
|
||||||
|
|
||||||
|
int x = 0, y = 0;
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
if (key.diskState[i] != DiskState.NONE) {
|
if (key.diskState[i] != DiskState.NONE) {
|
||||||
quads.addAll(disks.get(facing).get(key.diskState[i]).get(i).getQuads(key.state, key.side, key.random));
|
IBakedModel diskModel = getDiskModel(key.diskState[i]);
|
||||||
|
|
||||||
|
quads.addAll(QuadTransformer.getTransformedQuads(
|
||||||
|
diskModel,
|
||||||
|
facing,
|
||||||
|
getDiskTranslation(facing, x, y),
|
||||||
|
key.state,
|
||||||
|
key.random,
|
||||||
|
key.side
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
y++;
|
||||||
|
if ((i + 1) % 3 == 0) {
|
||||||
|
x++;
|
||||||
|
y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,56 +116,42 @@ public class DiskManipulatorBakedModel extends DelegateBakedModel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
public DiskManipulatorBakedModel(IBakedModel baseConnected,
|
public DiskManipulatorBakedModel(IBakedModel baseConnected, IBakedModel baseDisconnected, IBakedModel disk, IBakedModel diskNearCapacity, IBakedModel diskFull, IBakedModel diskDisconnected) {
|
||||||
IBakedModel baseDisconnected,
|
|
||||||
IBakedModel disk,
|
|
||||||
IBakedModel diskNearCapacity,
|
|
||||||
IBakedModel diskFull,
|
|
||||||
IBakedModel diskDisconnected) {
|
|
||||||
super(baseDisconnected);
|
super(baseDisconnected);
|
||||||
|
|
||||||
for (Direction facing : Direction.values()) {
|
this.baseConnected = baseConnected;
|
||||||
if (facing.getHorizontalIndex() == -1) {
|
this.baseDisconnected = baseDisconnected;
|
||||||
continue;
|
this.disk = disk;
|
||||||
|
this.diskNearCapacity = diskNearCapacity;
|
||||||
|
this.diskFull = diskFull;
|
||||||
|
this.diskDisconnected = diskDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
modelsConnected.put(facing, new TRSRBakedModel(baseConnected, facing));
|
private IBakedModel getDiskModel(DiskState diskState) {
|
||||||
modelsDisconnected.put(facing, new TRSRBakedModel(baseDisconnected, facing));
|
switch (diskState) {
|
||||||
|
case DISCONNECTED:
|
||||||
disks.put(facing, new HashMap<>());
|
return diskDisconnected;
|
||||||
|
case NEAR_CAPACITY:
|
||||||
disks.get(facing).put(DiskState.NORMAL, new ArrayList<>());
|
return diskNearCapacity;
|
||||||
disks.get(facing).put(DiskState.NEAR_CAPACITY, new ArrayList<>());
|
case FULL:
|
||||||
disks.get(facing).put(DiskState.FULL, new ArrayList<>());
|
return diskFull;
|
||||||
disks.get(facing).put(DiskState.DISCONNECTED, new ArrayList<>());
|
default:
|
||||||
|
return disk;
|
||||||
addDiskModels(disk, DiskState.NORMAL, facing);
|
|
||||||
addDiskModels(diskNearCapacity, DiskState.NEAR_CAPACITY, facing);
|
|
||||||
addDiskModels(diskFull, DiskState.FULL, facing);
|
|
||||||
addDiskModels(diskDisconnected, DiskState.DISCONNECTED, facing);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDiskModels(IBakedModel disk, DiskState type, Direction facing) {
|
private Vector3f getDiskTranslation(Direction facing, int x, int y) {
|
||||||
for (int x = 0; x < 2; ++x) {
|
Vector3f translation = new Vector3f();
|
||||||
for (int y = 0; y < 3; ++y) {
|
|
||||||
TRSRBakedModel model = new TRSRBakedModel(disk, facing);
|
|
||||||
|
|
||||||
Vector3f trans = model.transformation.getTranslation();
|
|
||||||
|
|
||||||
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
|
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
|
||||||
trans.add((2F / 16F + ((float) x * 7F) / 16F) * (facing == Direction.NORTH ? -1 : 1), 0, 0); // Add to X
|
translation.add((2F / 16F + ((float) x * 7F) / 16F) * (facing == Direction.NORTH ? -1 : 1), 0, 0); // Add to X
|
||||||
} else if (facing == Direction.EAST || facing == Direction.WEST) {
|
} else if (facing == Direction.EAST || facing == Direction.WEST) {
|
||||||
trans.add(0, 0, (2F / 16F + ((float) x * 7F) / 16F) * (facing == Direction.EAST ? -1 : 1)); // Add to Z
|
translation.add(0, 0, (2F / 16F + ((float) x * 7F) / 16F) * (facing == Direction.EAST ? -1 : 1)); // Add to Z
|
||||||
}
|
}
|
||||||
|
|
||||||
trans.add(0, -((6F / 16F) + (3F * y) / 16F), 0); // Remove from Y
|
translation.add(0, -((6F / 16F) + (3F * y) / 16F), 0); // Remove from Y
|
||||||
|
|
||||||
model.transformation = new TransformationMatrix(trans, model.transformation.getRotationLeft(), model.transformation.getScale(), model.transformation.getRightRot());
|
return translation;
|
||||||
|
|
||||||
disks.get(facing).get(type).add(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class DiskManipulatorTile extends NetworkNodeTile<DiskManipulatorNetworkN
|
|||||||
|
|
||||||
private final LazyOptional<IItemHandler> diskCapability = LazyOptional.of(() -> getNode().getDisks());
|
private final LazyOptional<IItemHandler> diskCapability = LazyOptional.of(() -> getNode().getDisks());
|
||||||
|
|
||||||
private final DiskState[] diskState = new DiskState[8];
|
private final DiskState[] diskState = new DiskState[6];
|
||||||
|
|
||||||
public DiskManipulatorTile() {
|
public DiskManipulatorTile() {
|
||||||
super(RSTiles.DISK_MANIPULATOR);
|
super(RSTiles.DISK_MANIPULATOR);
|
||||||
|
|||||||
Reference in New Issue
Block a user