Refactor the cable collision system.

This commit is contained in:
raoulvdberge
2018-07-08 23:28:09 +02:00
parent cce26d0276
commit 0751e6c7c9
28 changed files with 444 additions and 403 deletions

View File

@@ -5,7 +5,10 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.node.ICoverable;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.Cover;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.collision.AdvancedRayTraceResult;
import com.raoulvdberge.refinedstorage.render.collision.AdvancedRayTracer;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.tile.TileBase;
import com.raoulvdberge.refinedstorage.tile.TileCable;
import com.raoulvdberge.refinedstorage.tile.TileNode;
@@ -39,12 +42,12 @@ public class BlockCable extends BlockNode {
public static final PropertyObject<Cover> COVER_UP = new PropertyObject<>("cover_up", Cover.class);
public static final PropertyObject<Cover> COVER_DOWN = new PropertyObject<>("cover_down", Cover.class);
protected static final PropertyBool NORTH = PropertyBool.create("north");
protected static final PropertyBool EAST = PropertyBool.create("east");
protected static final PropertyBool SOUTH = PropertyBool.create("south");
protected static final PropertyBool WEST = PropertyBool.create("west");
protected static final PropertyBool UP = PropertyBool.create("up");
protected static final PropertyBool DOWN = PropertyBool.create("down");
private static final PropertyBool NORTH = PropertyBool.create("north");
private static final PropertyBool EAST = PropertyBool.create("east");
private static final PropertyBool SOUTH = PropertyBool.create("south");
private static final PropertyBool WEST = PropertyBool.create("west");
private static final PropertyBool UP = PropertyBool.create("up");
private static final PropertyBool DOWN = PropertyBool.create("down");
public BlockCable(String name) {
super(name);
@@ -153,68 +156,56 @@ public class BlockCable extends BlockNode {
return false;
}
protected boolean hitCablePart(IBlockState state, World world, BlockPos pos, float hitX, float hitY, float hitZ) {
protected boolean canAccessGui(IBlockState state, World world, BlockPos pos, float hitX, float hitY, float hitZ) {
state = getActualState(state, world, pos);
if ((RenderUtils.isInBounds(ConstantsCable.CORE_AABB, hitX, hitY, hitZ)) ||
(state.getValue(NORTH) && RenderUtils.isInBounds(ConstantsCable.NORTH_AABB, hitX, hitY, hitZ)) ||
(state.getValue(EAST) && RenderUtils.isInBounds(ConstantsCable.EAST_AABB, hitX, hitY, hitZ)) ||
(state.getValue(SOUTH) && RenderUtils.isInBounds(ConstantsCable.SOUTH_AABB, hitX, hitY, hitZ)) ||
(state.getValue(WEST) && RenderUtils.isInBounds(ConstantsCable.WEST_AABB, hitX, hitY, hitZ)) ||
(state.getValue(UP) && RenderUtils.isInBounds(ConstantsCable.UP_AABB, hitX, hitY, hitZ)) ||
(state.getValue(DOWN) && RenderUtils.isInBounds(ConstantsCable.DOWN_AABB, hitX, hitY, hitZ))) {
return true;
}
List<AxisAlignedBB> coverAabbs = getCoverCollisions(world.getTileEntity(pos));
for (AxisAlignedBB coverAabb : coverAabbs) {
if (RenderUtils.isInBounds(coverAabb, hitX, hitY, hitZ)) {
return true;
for (CollisionGroup group : getCollisions(world.getTileEntity(pos), state)) {
if (group.canAccessGui()) {
for (AxisAlignedBB aabb : group.getItems()) {
if (RenderUtils.isInBounds(aabb, hitX, hitY, hitZ)) {
return true;
}
}
}
}
return false;
}
public List<AxisAlignedBB> getCombinedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
List<CollisionGroup> groups = getCoverCollisions(tile);
boxes.add(ConstantsCable.CORE_AABB);
groups.add(ConstantsCable.CORE);
if (state.getValue(NORTH)) {
boxes.add(ConstantsCable.NORTH_AABB);
groups.add(ConstantsCable.NORTH);
}
if (state.getValue(EAST)) {
boxes.add(ConstantsCable.EAST_AABB);
groups.add(ConstantsCable.EAST);
}
if (state.getValue(SOUTH)) {
boxes.add(ConstantsCable.SOUTH_AABB);
groups.add(ConstantsCable.SOUTH);
}
if (state.getValue(WEST)) {
boxes.add(ConstantsCable.WEST_AABB);
groups.add(ConstantsCable.WEST);
}
if (state.getValue(UP)) {
boxes.add(ConstantsCable.UP_AABB);
groups.add(ConstantsCable.UP);
}
if (state.getValue(DOWN)) {
boxes.add(ConstantsCable.DOWN_AABB);
groups.add(ConstantsCable.DOWN);
}
return boxes;
return groups;
}
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
return getCoverCollisions(tile);
}
private List<AxisAlignedBB> getCoverCollisions(TileEntity tile) {
List<AxisAlignedBB> boxes = new ArrayList<>();
private List<CollisionGroup> getCoverCollisions(TileEntity tile) {
List<CollisionGroup> groups = new ArrayList<>();
if (tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable) {
CoverManager coverManager = ((ICoverable) ((TileNode) tile).getNode()).getCoverManager();
@@ -227,98 +218,91 @@ public class BlockCable extends BlockNode {
Cover coverDown = coverManager.getCover(EnumFacing.DOWN);
if (coverNorth != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
coverWest != null ? 2 : 0, coverDown != null ? 2 : 0, 0,
coverEast != null ? 14 : 16, coverUp != null ? 14 : 16, 2
));
)));
if (!coverNorth.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_NORTH_AABB);
groups.add(ConstantsCable.HOLDER_NORTH);
}
}
if (coverEast != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
14, coverDown != null ? 2 : 0, 0,
16, coverUp != null ? 14 : 16, 16
));
)));
if (!coverEast.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_EAST_AABB);
groups.add(ConstantsCable.HOLDER_EAST);
}
}
if (coverSouth != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
coverEast != null ? 14 : 16, coverDown != null ? 2 : 0, 16,
coverWest != null ? 2 : 0, coverUp != null ? 14 : 16, 14
));
)));
if (!coverSouth.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_SOUTH_AABB);
groups.add(ConstantsCable.HOLDER_SOUTH);
}
}
if (coverWest != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
0, coverDown != null ? 2 : 0, 0,
2, coverUp != null ? 14 : 16, 16
));
)));
if (!coverWest.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_WEST_AABB);
groups.add(ConstantsCable.HOLDER_WEST);
}
}
if (coverUp != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
0, 14, 0,
16, 16, 16
));
)));
if (!coverUp.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_UP_AABB);
groups.add(ConstantsCable.HOLDER_UP);
}
}
if (coverDown != null) {
boxes.add(RenderUtils.getBounds(
groups.add(new CollisionGroup().addItem(RenderUtils.getBounds(
0, 0, 0,
16, 2, 16
));
)));
if (!coverDown.getType().isHollow()) {
boxes.add(ConstantsCable.HOLDER_DOWN_AABB);
groups.add(ConstantsCable.HOLDER_DOWN);
}
}
}
return boxes;
}
private List<AxisAlignedBB> getAllCollisionBoxes(TileEntity tile, IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
boxes.addAll(getCombinedCollisionBoxes(state));
boxes.addAll(getCollisionBoxes(tile, state));
return boxes;
return groups;
}
@Override
@SuppressWarnings("deprecation")
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) {
for (AxisAlignedBB aabb : getAllCollisionBoxes(world.getTileEntity(pos), this.getActualState(state, world, pos))) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
for (CollisionGroup group : getCollisions(world.getTileEntity(pos), this.getActualState(state, world, pos))) {
for (AxisAlignedBB aabb : group.getItems()) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
}
@Override
@SuppressWarnings("deprecation")
public RayTraceResult collisionRayTrace(IBlockState state, World world, BlockPos pos, Vec3d start, Vec3d end) {
RenderUtils.AdvancedRayTraceResult result = RenderUtils.collisionRayTrace(pos, start, end, getAllCollisionBoxes(world.getTileEntity(pos), this.getActualState(state, world, pos)));
AdvancedRayTraceResult result = AdvancedRayTracer.rayTrace(pos, start, end, getCollisions(world.getTileEntity(pos), this.getActualState(state, world, pos)));
return result != null ? result.hit : null;
return result != null ? result.getHit() : null;
}
@Override

View File

@@ -1,15 +1,15 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsConstructor;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsConstructor;
import com.raoulvdberge.refinedstorage.tile.TileConstructor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -22,37 +22,37 @@ public class BlockConstructor extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
List<AxisAlignedBB> boxes = super.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
List<CollisionGroup> groups = super.getCollisions(tile, state);
switch (state.getValue(getDirection().getProperty())) {
case NORTH:
boxes.add(ConstantsCable.HOLDER_NORTH_AABB);
boxes.add(ConstantsConstructor.HEAD_NORTH_AABB);
groups.add(ConstantsCable.HOLDER_NORTH);
groups.add(ConstantsConstructor.HEAD_NORTH);
break;
case EAST:
boxes.add(ConstantsCable.HOLDER_EAST_AABB);
boxes.add(ConstantsConstructor.HEAD_EAST_AABB);
groups.add(ConstantsCable.HOLDER_EAST);
groups.add(ConstantsConstructor.HEAD_EAST);
break;
case SOUTH:
boxes.add(ConstantsCable.HOLDER_SOUTH_AABB);
boxes.add(ConstantsConstructor.HEAD_SOUTH_AABB);
groups.add(ConstantsCable.HOLDER_SOUTH);
groups.add(ConstantsConstructor.HEAD_SOUTH);
break;
case WEST:
boxes.add(ConstantsCable.HOLDER_WEST_AABB);
boxes.add(ConstantsConstructor.HEAD_WEST_AABB);
groups.add(ConstantsCable.HOLDER_WEST);
groups.add(ConstantsConstructor.HEAD_WEST);
break;
case UP:
boxes.add(ConstantsCable.HOLDER_UP_AABB);
boxes.add(ConstantsConstructor.HEAD_UP_AABB);
groups.add(ConstantsCable.HOLDER_UP);
groups.add(ConstantsConstructor.HEAD_UP);
break;
case DOWN:
boxes.add(ConstantsCable.HOLDER_DOWN_AABB);
boxes.add(ConstantsConstructor.HEAD_DOWN_AABB);
groups.add(ConstantsCable.HOLDER_DOWN);
groups.add(ConstantsConstructor.HEAD_DOWN);
break;
}
return boxes;
return groups;
}
@Override
@@ -62,7 +62,7 @@ public class BlockConstructor extends BlockCable {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -2,13 +2,13 @@ package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.tile.TileDestructor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -26,13 +26,13 @@ public class BlockDestructor extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisions(tile, state);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -1,7 +1,7 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDetector;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsDetector;
import com.raoulvdberge.refinedstorage.tile.TileDetector;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;

View File

@@ -1,14 +1,14 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsExporter;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsExporter;
import com.raoulvdberge.refinedstorage.tile.TileExporter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -21,43 +21,31 @@ public class BlockExporter extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
List<AxisAlignedBB> boxes = super.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
List<CollisionGroup> groups = super.getCollisions(tile, state);
switch (state.getValue(getDirection().getProperty())) {
case NORTH:
boxes.add(ConstantsExporter.LINE_NORTH_1_AABB);
boxes.add(ConstantsExporter.LINE_NORTH_2_AABB);
boxes.add(ConstantsExporter.LINE_NORTH_3_AABB);
groups.add(ConstantsExporter.LINE_NORTH);
break;
case EAST:
boxes.add(ConstantsExporter.LINE_EAST_1_AABB);
boxes.add(ConstantsExporter.LINE_EAST_2_AABB);
boxes.add(ConstantsExporter.LINE_EAST_3_AABB);
groups.add(ConstantsExporter.LINE_EAST);
break;
case SOUTH:
boxes.add(ConstantsExporter.LINE_SOUTH_1_AABB);
boxes.add(ConstantsExporter.LINE_SOUTH_2_AABB);
boxes.add(ConstantsExporter.LINE_SOUTH_3_AABB);
groups.add(ConstantsExporter.LINE_SOUTH);
break;
case WEST:
boxes.add(ConstantsExporter.LINE_WEST_1_AABB);
boxes.add(ConstantsExporter.LINE_WEST_2_AABB);
boxes.add(ConstantsExporter.LINE_WEST_3_AABB);
groups.add(ConstantsExporter.LINE_WEST);
break;
case UP:
boxes.add(ConstantsExporter.LINE_UP_1_AABB);
boxes.add(ConstantsExporter.LINE_UP_2_AABB);
boxes.add(ConstantsExporter.LINE_UP_3_AABB);
groups.add(ConstantsExporter.LINE_UP);
break;
case DOWN:
boxes.add(ConstantsExporter.LINE_DOWN_1_AABB);
boxes.add(ConstantsExporter.LINE_DOWN_2_AABB);
boxes.add(ConstantsExporter.LINE_DOWN_3_AABB);
groups.add(ConstantsExporter.LINE_DOWN);
break;
}
return boxes;
return groups;
}
@Override
@@ -67,7 +55,7 @@ public class BlockExporter extends BlockCable {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -2,8 +2,9 @@ package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeExternalStorage;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsExternalStorage;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsExternalStorage;
import com.raoulvdberge.refinedstorage.tile.TileExternalStorage;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -11,7 +12,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -24,37 +24,37 @@ public class BlockExternalStorage extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
List<AxisAlignedBB> boxes = super.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
List<CollisionGroup> groups = super.getCollisions(tile, state);
switch (state.getValue(getDirection().getProperty())) {
case NORTH:
boxes.add(ConstantsCable.HOLDER_NORTH_AABB);
boxes.add(ConstantsExternalStorage.HEAD_NORTH_AABB);
groups.add(ConstantsCable.HOLDER_NORTH);
groups.add(ConstantsExternalStorage.HEAD_NORTH);
break;
case EAST:
boxes.add(ConstantsCable.HOLDER_EAST_AABB);
boxes.add(ConstantsExternalStorage.HEAD_EAST_AABB);
groups.add(ConstantsCable.HOLDER_EAST);
groups.add(ConstantsExternalStorage.HEAD_EAST);
break;
case SOUTH:
boxes.add(ConstantsCable.HOLDER_SOUTH_AABB);
boxes.add(ConstantsExternalStorage.HEAD_SOUTH_AABB);
groups.add(ConstantsCable.HOLDER_SOUTH);
groups.add(ConstantsExternalStorage.HEAD_SOUTH);
break;
case WEST:
boxes.add(ConstantsCable.HOLDER_WEST_AABB);
boxes.add(ConstantsExternalStorage.HEAD_WEST_AABB);
groups.add(ConstantsCable.HOLDER_WEST);
groups.add(ConstantsExternalStorage.HEAD_WEST);
break;
case UP:
boxes.add(ConstantsCable.HOLDER_UP_AABB);
boxes.add(ConstantsExternalStorage.HEAD_UP_AABB);
groups.add(ConstantsCable.HOLDER_UP);
groups.add(ConstantsExternalStorage.HEAD_UP);
break;
case DOWN:
boxes.add(ConstantsCable.HOLDER_DOWN_AABB);
boxes.add(ConstantsExternalStorage.HEAD_DOWN_AABB);
groups.add(ConstantsCable.HOLDER_DOWN);
groups.add(ConstantsExternalStorage.HEAD_DOWN);
break;
}
return boxes;
return groups;
}
@Override
@@ -64,7 +64,7 @@ public class BlockExternalStorage extends BlockCable {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -1,14 +1,14 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsImporter;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsImporter;
import com.raoulvdberge.refinedstorage.tile.TileImporter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -21,43 +21,31 @@ public class BlockImporter extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
List<AxisAlignedBB> boxes = super.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
List<CollisionGroup> groups = super.getCollisions(tile, state);
switch (state.getValue(getDirection().getProperty())) {
case NORTH:
boxes.add(ConstantsImporter.LINE_NORTH_1_AABB);
boxes.add(ConstantsImporter.LINE_NORTH_2_AABB);
boxes.add(ConstantsImporter.LINE_NORTH_3_AABB);
groups.add(ConstantsImporter.LINE_NORTH);
break;
case EAST:
boxes.add(ConstantsImporter.LINE_EAST_1_AABB);
boxes.add(ConstantsImporter.LINE_EAST_2_AABB);
boxes.add(ConstantsImporter.LINE_EAST_3_AABB);
groups.add(ConstantsImporter.LINE_EAST);
break;
case SOUTH:
boxes.add(ConstantsImporter.LINE_SOUTH_1_AABB);
boxes.add(ConstantsImporter.LINE_SOUTH_2_AABB);
boxes.add(ConstantsImporter.LINE_SOUTH_3_AABB);
groups.add(ConstantsImporter.LINE_SOUTH);
break;
case WEST:
boxes.add(ConstantsImporter.LINE_WEST_1_AABB);
boxes.add(ConstantsImporter.LINE_WEST_2_AABB);
boxes.add(ConstantsImporter.LINE_WEST_3_AABB);
groups.add(ConstantsImporter.LINE_WEST);
break;
case UP:
boxes.add(ConstantsImporter.LINE_UP_1_AABB);
boxes.add(ConstantsImporter.LINE_UP_2_AABB);
boxes.add(ConstantsImporter.LINE_UP_3_AABB);
groups.add(ConstantsImporter.LINE_UP);
break;
case DOWN:
boxes.add(ConstantsImporter.LINE_DOWN_1_AABB);
boxes.add(ConstantsImporter.LINE_DOWN_2_AABB);
boxes.add(ConstantsImporter.LINE_DOWN_3_AABB);
groups.add(ConstantsImporter.LINE_DOWN);
break;
}
return boxes;
return groups;
}
@Override
@@ -67,7 +55,7 @@ public class BlockImporter extends BlockCable {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.item.ItemBlockPortableGrid;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsPortableGrid;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsPortableGrid;
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;

View File

@@ -4,13 +4,13 @@ import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeReader;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.tile.TileReader;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -24,13 +24,13 @@ public class BlockReader extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisions(tile, state);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -1,7 +1,7 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsWirelessTransmitter;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsWirelessTransmitter;
import com.raoulvdberge.refinedstorage.tile.TileWirelessTransmitter;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockFaceShape;

View File

@@ -5,13 +5,13 @@ import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IWriter;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeWriter;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.tile.TileWriter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -25,13 +25,13 @@ public class BlockWriter extends BlockCable {
}
@Override
public List<AxisAlignedBB> getCollisionBoxes(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisionBoxes(tile, state);
public List<CollisionGroup> getCollisions(TileEntity tile, IBlockState state) {
return RSBlocks.CONSTRUCTOR.getCollisions(tile, state);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}

View File

@@ -15,6 +15,7 @@ import com.raoulvdberge.refinedstorage.gui.grid.GuiCraftingStart;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
import com.raoulvdberge.refinedstorage.item.*;
import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse;
import com.raoulvdberge.refinedstorage.render.collision.BlockHighlightListener;
import com.raoulvdberge.refinedstorage.render.model.ModelDiskDrive;
import com.raoulvdberge.refinedstorage.render.model.ModelDiskManipulator;
import com.raoulvdberge.refinedstorage.render.model.baked.BakedModelCableCover;
@@ -27,41 +28,30 @@ import com.raoulvdberge.refinedstorage.tile.TileController;
import com.raoulvdberge.refinedstorage.tile.TileStorageMonitor;
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.List;
import java.util.UUID;
public class ProxyClient extends ProxyCommon {
@@ -69,6 +59,8 @@ public class ProxyClient extends ProxyCommon {
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
MinecraftForge.EVENT_BUS.register(new BlockHighlightListener());
ClientRegistry.bindTileEntitySpecialRenderer(TileStorageMonitor.class, new TileEntitySpecialRendererStorageMonitor());
}
@@ -389,97 +381,4 @@ public class ProxyClient extends ProxyCommon {
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onBlockDrawHighlight(DrawBlockHighlightEvent e) {
if (e.getTarget() == null || e.getTarget().getBlockPos() == null) {
return;
}
EntityPlayer player = e.getPlayer();
BlockPos pos = e.getTarget().getBlockPos();
Block block = player.getEntityWorld().getBlockState(pos).getBlock();
if (!(block instanceof BlockCable)) {
return;
}
BlockCable cable = (BlockCable) block;
IBlockState state = cable.getActualState(cable.getDefaultState(), player.getEntityWorld(), pos);
if (cable.collisionRayTrace(state, player.getEntityWorld(), pos, RenderUtils.getStart(player), RenderUtils.getEnd(player)) == null) {
return;
}
List<AxisAlignedBB> combinedBoxes = cable.getCombinedCollisionBoxes(state);
List<AxisAlignedBB> boxes = cable.getCollisionBoxes(player.world.getTileEntity(pos), state);
e.setCanceled(true);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) e.getPartialTicks();
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) e.getPartialTicks();
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) e.getPartialTicks();
AxisAlignedBB combinedAabb = combinedBoxes.get(0);
for (int i = 1; i < combinedBoxes.size(); ++i) {
combinedAabb = combinedAabb.union(combinedBoxes.get(i));
}
drawSelectionBoundingBox(combinedAabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ()));
for (AxisAlignedBB aabb : boxes) {
drawSelectionBoundingBox(aabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ()));
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
private void drawSelectionBoundingBox(AxisAlignedBB aabb) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(3, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
tessellator.draw();
buffer.begin(3, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
tessellator.draw();
buffer.begin(1, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
tessellator.draw();
}
}

View File

@@ -0,0 +1,37 @@
package com.raoulvdberge.refinedstorage.render.collision;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
public class AdvancedRayTraceResult<T extends RayTraceResult> {
private CollisionGroup group;
private AxisAlignedBB bounds;
private T hit;
public AdvancedRayTraceResult(CollisionGroup group, AxisAlignedBB bounds, T hit) {
this.group = group;
this.bounds = bounds;
this.hit = hit;
}
public boolean valid() {
return hit != null && bounds != null;
}
public double squareDistanceTo(Vec3d vec) {
return hit.hitVec.squareDistanceTo(vec);
}
public CollisionGroup getGroup() {
return group;
}
public AxisAlignedBB getBounds() {
return bounds;
}
public T getHit() {
return hit;
}
}

View File

@@ -0,0 +1,63 @@
package com.raoulvdberge.refinedstorage.render.collision;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import java.util.Collection;
public final class AdvancedRayTracer {
public static Vec3d getStart(EntityPlayer player) {
return new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
}
public static Vec3d getEnd(EntityPlayer player) {
double reachDistance = player instanceof EntityPlayerMP ? player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue() : (player.capabilities.isCreativeMode ? 5.0D : 4.5D);
Vec3d lookVec = player.getLookVec();
Vec3d start = getStart(player);
return start.addVector(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
}
public static AdvancedRayTraceResult<RayTraceResult> rayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<CollisionGroup> groups) {
double minDistance = Double.POSITIVE_INFINITY;
AdvancedRayTraceResult hit = null;
int i = -1;
for (CollisionGroup group : groups) {
for (AxisAlignedBB aabb : group.getItems()) {
AdvancedRayTraceResult result = rayTrace(pos, start, end, aabb, i, group);
if (result != null) {
double d = result.squareDistanceTo(start);
if (d < minDistance) {
minDistance = d;
hit = result;
}
}
i++;
}
}
return hit;
}
public static AdvancedRayTraceResult<RayTraceResult> rayTrace(BlockPos pos, Vec3d start, Vec3d end, AxisAlignedBB bounds, int subHit, CollisionGroup group) {
RayTraceResult result = bounds.offset(pos).calculateIntercept(start, end);
if (result == null) {
return null;
}
result = new RayTraceResult(RayTraceResult.Type.BLOCK, result.hitVec, result.sideHit, pos);
result.subHit = subHit;
return new AdvancedRayTraceResult<>(group, bounds, result);
}
}

View File

@@ -0,0 +1,106 @@
package com.raoulvdberge.refinedstorage.render.collision;
import com.raoulvdberge.refinedstorage.block.BlockCable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class BlockHighlightListener {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onBlockDrawHighlight(DrawBlockHighlightEvent e) {
if (e.getTarget() == null || e.getTarget().getBlockPos() == null) {
return;
}
EntityPlayer player = e.getPlayer();
BlockPos pos = e.getTarget().getBlockPos();
Block block = player.getEntityWorld().getBlockState(pos).getBlock();
if (!(block instanceof BlockCable)) {
return;
}
BlockCable cable = (BlockCable) block;
IBlockState state = cable.getActualState(cable.getDefaultState(), player.getEntityWorld(), pos);
AdvancedRayTraceResult result = AdvancedRayTracer.rayTrace(
pos,
AdvancedRayTracer.getStart(player),
AdvancedRayTracer.getEnd(player),
cable.getCollisions(player.getEntityWorld().getTileEntity(pos), state)
);
e.setCanceled(true);
if (result == null) {
return;
}
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
GlStateManager.glLineWidth(3.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) e.getPartialTicks();
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) e.getPartialTicks();
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) e.getPartialTicks();
for (AxisAlignedBB aabb : result.getGroup().getItems()) {
drawSelectionBoundingBox(aabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ()));
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
private void drawSelectionBoundingBox(AxisAlignedBB aabb) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(3, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
tessellator.draw();
buffer.begin(3, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
tessellator.draw();
buffer.begin(1, DefaultVertexFormats.POSITION);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
tessellator.draw();
}
}

View File

@@ -0,0 +1,31 @@
package com.raoulvdberge.refinedstorage.render.collision;
import net.minecraft.util.math.AxisAlignedBB;
import java.util.ArrayList;
import java.util.List;
public class CollisionGroup {
private List<AxisAlignedBB> items = new ArrayList<>();
private boolean canAccessGui;
public CollisionGroup addItem(AxisAlignedBB item) {
items.add(item);
return this;
}
public List<AxisAlignedBB> getItems() {
return items;
}
public boolean canAccessGui() {
return canAccessGui;
}
public CollisionGroup setCanAccessGui(boolean canAccessGui) {
this.canAccessGui = canAccessGui;
return this;
}
}

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
@@ -7,20 +8,20 @@ import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.util.vector.Vector3f;
public final class ConstantsCable {
public static final AxisAlignedBB CORE_AABB = RenderUtils.getBounds(6, 6, 6, 10, 10, 10);
public static final AxisAlignedBB NORTH_AABB = RenderUtils.getBounds(6, 6, 0, 10, 10, 6);
public static final AxisAlignedBB EAST_AABB = RenderUtils.getBounds(10, 6, 6, 16, 10, 10);
public static final AxisAlignedBB SOUTH_AABB = RenderUtils.getBounds(6, 6, 10, 10, 10, 16);
public static final AxisAlignedBB WEST_AABB = RenderUtils.getBounds(0, 6, 6, 6, 10, 10);
public static final AxisAlignedBB UP_AABB = RenderUtils.getBounds(6, 10, 6, 10, 16, 10);
public static final AxisAlignedBB DOWN_AABB = RenderUtils.getBounds(6, 0, 6, 10, 6, 10);
public static final CollisionGroup CORE = new CollisionGroup().addItem(RenderUtils.getBounds(6, 6, 6, 10, 10, 10));
public static final CollisionGroup NORTH = new CollisionGroup().addItem(RenderUtils.getBounds(6, 6, 0, 10, 10, 6));
public static final CollisionGroup EAST = new CollisionGroup().addItem(RenderUtils.getBounds(10, 6, 6, 16, 10, 10));
public static final CollisionGroup SOUTH = new CollisionGroup().addItem(RenderUtils.getBounds(6, 6, 10, 10, 10, 16));
public static final CollisionGroup WEST = new CollisionGroup().addItem(RenderUtils.getBounds(0, 6, 6, 6, 10, 10));
public static final CollisionGroup UP = new CollisionGroup().addItem(RenderUtils.getBounds(6, 10, 6, 10, 16, 10));
public static final CollisionGroup DOWN = new CollisionGroup().addItem(RenderUtils.getBounds(6, 0, 6, 10, 6, 10));
public static final AxisAlignedBB HOLDER_NORTH_AABB = getHolderBoundsAabb(EnumFacing.NORTH);
public static final AxisAlignedBB HOLDER_EAST_AABB = getHolderBoundsAabb(EnumFacing.EAST);
public static final AxisAlignedBB HOLDER_SOUTH_AABB = getHolderBoundsAabb(EnumFacing.SOUTH);
public static final AxisAlignedBB HOLDER_WEST_AABB = getHolderBoundsAabb(EnumFacing.WEST);
public static final AxisAlignedBB HOLDER_UP_AABB = getHolderBoundsAabb(EnumFacing.UP);
public static final AxisAlignedBB HOLDER_DOWN_AABB = getHolderBoundsAabb(EnumFacing.DOWN);
public static final CollisionGroup HOLDER_NORTH = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.NORTH));
public static final CollisionGroup HOLDER_EAST = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.EAST));
public static final CollisionGroup HOLDER_SOUTH = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.SOUTH));
public static final CollisionGroup HOLDER_WEST = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.WEST));
public static final CollisionGroup HOLDER_UP = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.UP));
public static final CollisionGroup HOLDER_DOWN = new CollisionGroup().addItem(getHolderBoundsAabb(EnumFacing.DOWN));
public static Pair<Vector3f, Vector3f> getCoverBounds(EnumFacing side) {
switch (side) {

View File

@@ -0,0 +1,13 @@
package com.raoulvdberge.refinedstorage.render.collision.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
public final class ConstantsConstructor {
public static final CollisionGroup HEAD_NORTH = new CollisionGroup().addItem(RenderUtils.getBounds(2, 2, 0, 14, 14, 2)).setCanAccessGui(true);
public static final CollisionGroup HEAD_EAST = new CollisionGroup().addItem(RenderUtils.getBounds(14, 2, 2, 16, 14, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_SOUTH = new CollisionGroup().addItem(RenderUtils.getBounds(2, 2, 14, 14, 14, 16)).setCanAccessGui(true);
public static final CollisionGroup HEAD_WEST = new CollisionGroup().addItem(RenderUtils.getBounds(0, 2, 2, 2, 14, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_DOWN = new CollisionGroup().addItem(RenderUtils.getBounds(2, 0, 2, 14, 2, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_UP = new CollisionGroup().addItem(RenderUtils.getBounds(2, 14, 2, 14, 16, 14)).setCanAccessGui(true);
}

View File

@@ -1,4 +1,4 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import net.minecraft.util.math.AxisAlignedBB;

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.util.math.AxisAlignedBB;
@@ -7,19 +8,30 @@ public final class ConstantsExporter {
public static final AxisAlignedBB LINE_NORTH_1_AABB = RenderUtils.getBounds(6, 6, 0, 10, 10, 2);
public static final AxisAlignedBB LINE_NORTH_2_AABB = RenderUtils.getBounds(5, 5, 2, 11, 11, 4);
public static final AxisAlignedBB LINE_NORTH_3_AABB = RenderUtils.getBounds(3, 3, 4, 13, 13, 6);
public static final CollisionGroup LINE_NORTH = new CollisionGroup().addItem(LINE_NORTH_1_AABB).addItem(LINE_NORTH_2_AABB).addItem(LINE_NORTH_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_EAST_1_AABB = RenderUtils.getBounds(14, 6, 6, 16, 10, 10);
public static final AxisAlignedBB LINE_EAST_2_AABB = RenderUtils.getBounds(12, 5, 5, 14, 11, 11);
public static final AxisAlignedBB LINE_EAST_3_AABB = RenderUtils.getBounds(10, 3, 3, 12, 13, 13);
public static final CollisionGroup LINE_EAST = new CollisionGroup().addItem(LINE_EAST_1_AABB).addItem(LINE_EAST_2_AABB).addItem(LINE_EAST_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_SOUTH_1_AABB = RenderUtils.getBounds(6, 6, 14, 10, 10, 16);
public static final AxisAlignedBB LINE_SOUTH_2_AABB = RenderUtils.getBounds(5, 5, 12, 11, 11, 14);
public static final AxisAlignedBB LINE_SOUTH_3_AABB = RenderUtils.getBounds(3, 3, 10, 13, 13, 12);
public static final CollisionGroup LINE_SOUTH = new CollisionGroup().addItem(LINE_SOUTH_1_AABB).addItem(LINE_SOUTH_2_AABB).addItem(LINE_SOUTH_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_WEST_1_AABB = RenderUtils.getBounds(0, 6, 6, 2, 10, 10);
public static final AxisAlignedBB LINE_WEST_2_AABB = RenderUtils.getBounds(2, 5, 5, 4, 11, 11);
public static final AxisAlignedBB LINE_WEST_3_AABB = RenderUtils.getBounds(4, 3, 3, 6, 13, 13);
public static final CollisionGroup LINE_WEST = new CollisionGroup().addItem(LINE_WEST_1_AABB).addItem(LINE_WEST_2_AABB).addItem(LINE_WEST_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_UP_1_AABB = RenderUtils.getBounds(6, 14, 6, 10, 16, 10);
public static final AxisAlignedBB LINE_UP_2_AABB = RenderUtils.getBounds(5, 12, 5, 11, 14, 11);
public static final AxisAlignedBB LINE_UP_3_AABB = RenderUtils.getBounds(3, 10, 3, 13, 12, 13);
public static final CollisionGroup LINE_UP = new CollisionGroup().addItem(LINE_UP_1_AABB).addItem(LINE_UP_2_AABB).addItem(LINE_UP_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_DOWN_1_AABB = RenderUtils.getBounds(6, 0, 6, 10, 2, 10);
public static final AxisAlignedBB LINE_DOWN_2_AABB = RenderUtils.getBounds(5, 2, 5, 11, 4, 11);
public static final AxisAlignedBB LINE_DOWN_3_AABB = RenderUtils.getBounds(3, 4, 3, 13, 6, 13);
public static final CollisionGroup LINE_DOWN = new CollisionGroup().addItem(LINE_DOWN_1_AABB).addItem(LINE_DOWN_2_AABB).addItem(LINE_DOWN_3_AABB).setCanAccessGui(true);
}

View File

@@ -0,0 +1,13 @@
package com.raoulvdberge.refinedstorage.render.collision.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
public final class ConstantsExternalStorage {
public static final CollisionGroup HEAD_NORTH = new CollisionGroup().addItem(RenderUtils.getBounds(3, 3, 0, 13, 13, 2)).setCanAccessGui(true);
public static final CollisionGroup HEAD_EAST = new CollisionGroup().addItem(RenderUtils.getBounds(14, 3, 3, 16, 13, 13)).setCanAccessGui(true);
public static final CollisionGroup HEAD_SOUTH = new CollisionGroup().addItem(RenderUtils.getBounds(3, 3, 14, 13, 13, 16)).setCanAccessGui(true);
public static final CollisionGroup HEAD_WEST = new CollisionGroup().addItem(RenderUtils.getBounds(0, 3, 3, 2, 13, 13)).setCanAccessGui(true);
public static final CollisionGroup HEAD_UP = new CollisionGroup().addItem(RenderUtils.getBounds(3, 14, 3, 13, 16, 13)).setCanAccessGui(true);
public static final CollisionGroup HEAD_DOWN = new CollisionGroup().addItem(RenderUtils.getBounds(3, 0, 3, 13, 2, 13)).setCanAccessGui(true);
}

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.util.math.AxisAlignedBB;
@@ -7,19 +8,30 @@ public final class ConstantsImporter {
public static final AxisAlignedBB LINE_NORTH_1_AABB = RenderUtils.getBounds(6, 6, 4, 10, 10, 6);
public static final AxisAlignedBB LINE_NORTH_2_AABB = RenderUtils.getBounds(5, 5, 2, 11, 11, 4);
public static final AxisAlignedBB LINE_NORTH_3_AABB = RenderUtils.getBounds(3, 3, 0, 13, 13, 2);
public static final CollisionGroup LINE_NORTH = new CollisionGroup().addItem(LINE_NORTH_1_AABB).addItem(LINE_NORTH_2_AABB).addItem(LINE_NORTH_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_EAST_1_AABB = RenderUtils.getBounds(10, 6, 6, 12, 10, 10);
public static final AxisAlignedBB LINE_EAST_2_AABB = RenderUtils.getBounds(12, 5, 5, 14, 11, 11);
public static final AxisAlignedBB LINE_EAST_3_AABB = RenderUtils.getBounds(14, 3, 3, 16, 13, 13);
public static final CollisionGroup LINE_EAST = new CollisionGroup().addItem(LINE_EAST_1_AABB).addItem(LINE_EAST_2_AABB).addItem(LINE_EAST_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_SOUTH_1_AABB = RenderUtils.getBounds(6, 6, 10, 10, 10, 12);
public static final AxisAlignedBB LINE_SOUTH_2_AABB = RenderUtils.getBounds(5, 5, 12, 11, 11, 14);
public static final AxisAlignedBB LINE_SOUTH_3_AABB = RenderUtils.getBounds(3, 3, 14, 13, 13, 16);
public static final CollisionGroup LINE_SOUTH = new CollisionGroup().addItem(LINE_SOUTH_1_AABB).addItem(LINE_SOUTH_2_AABB).addItem(LINE_SOUTH_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_WEST_1_AABB = RenderUtils.getBounds(4, 6, 6, 6, 10, 10);
public static final AxisAlignedBB LINE_WEST_2_AABB = RenderUtils.getBounds(2, 5, 5, 4, 11, 11);
public static final AxisAlignedBB LINE_WEST_3_AABB = RenderUtils.getBounds(0, 3, 3, 2, 13, 13);
public static final CollisionGroup LINE_WEST = new CollisionGroup().addItem(LINE_WEST_1_AABB).addItem(LINE_WEST_2_AABB).addItem(LINE_WEST_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_UP_1_AABB = RenderUtils.getBounds(6, 10, 6, 10, 12, 10);
public static final AxisAlignedBB LINE_UP_2_AABB = RenderUtils.getBounds(5, 12, 5, 11, 14, 11);
public static final AxisAlignedBB LINE_UP_3_AABB = RenderUtils.getBounds(3, 14, 3, 13, 16, 13);
public static final CollisionGroup LINE_UP = new CollisionGroup().addItem(LINE_UP_1_AABB).addItem(LINE_UP_2_AABB).addItem(LINE_UP_3_AABB).setCanAccessGui(true);
public static final AxisAlignedBB LINE_DOWN_1_AABB = RenderUtils.getBounds(6, 4, 6, 10, 6, 10);
public static final AxisAlignedBB LINE_DOWN_2_AABB = RenderUtils.getBounds(5, 2, 5, 11, 4, 11);
public static final AxisAlignedBB LINE_DOWN_3_AABB = RenderUtils.getBounds(3, 0, 3, 13, 2, 13);
public static final CollisionGroup LINE_DOWN = new CollisionGroup().addItem(LINE_DOWN_1_AABB).addItem(LINE_DOWN_2_AABB).addItem(LINE_DOWN_3_AABB).setCanAccessGui(true);
}

View File

@@ -1,4 +1,4 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import net.minecraft.util.math.AxisAlignedBB;

View File

@@ -1,4 +1,4 @@
package com.raoulvdberge.refinedstorage.render.constants;
package com.raoulvdberge.refinedstorage.render.collision.constants;
import net.minecraft.util.math.AxisAlignedBB;

View File

@@ -1,13 +0,0 @@
package com.raoulvdberge.refinedstorage.render.constants;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.util.math.AxisAlignedBB;
public final class ConstantsConstructor {
public static final AxisAlignedBB HEAD_NORTH_AABB = RenderUtils.getBounds(2, 2, 0, 14, 14, 2);
public static final AxisAlignedBB HEAD_EAST_AABB = RenderUtils.getBounds(14, 2, 2, 16, 14, 14);
public static final AxisAlignedBB HEAD_SOUTH_AABB = RenderUtils.getBounds(2, 2, 14, 14, 14, 16);
public static final AxisAlignedBB HEAD_WEST_AABB = RenderUtils.getBounds(0, 2, 2, 2, 14, 14);
public static final AxisAlignedBB HEAD_DOWN_AABB = RenderUtils.getBounds(2, 0, 2, 14, 2, 14);
public static final AxisAlignedBB HEAD_UP_AABB = RenderUtils.getBounds(2, 14, 2, 14, 16, 14);
}

View File

@@ -1,13 +0,0 @@
package com.raoulvdberge.refinedstorage.render.constants;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.util.math.AxisAlignedBB;
public final class ConstantsExternalStorage {
public static final AxisAlignedBB HEAD_NORTH_AABB = RenderUtils.getBounds(3, 3, 0, 13, 13, 2);
public static final AxisAlignedBB HEAD_EAST_AABB = RenderUtils.getBounds(14, 3, 3, 16, 13, 13);
public static final AxisAlignedBB HEAD_SOUTH_AABB = RenderUtils.getBounds(3, 3, 14, 13, 13, 16);
public static final AxisAlignedBB HEAD_WEST_AABB = RenderUtils.getBounds(0, 3, 3, 2, 13, 13);
public static final AxisAlignedBB HEAD_UP_AABB = RenderUtils.getBounds(3, 14, 3, 13, 16, 13);
public static final AxisAlignedBB HEAD_DOWN_AABB = RenderUtils.getBounds(3, 0, 3, 13, 2, 13);
}

View File

@@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.Cover;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.raoulvdberge.refinedstorage.block.BlockCable;
import com.raoulvdberge.refinedstorage.render.CubeBuilder;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.render.collision.constants.ConstantsCable;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;

View File

@@ -17,16 +17,11 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.MinecraftForgeClient;
@@ -44,7 +39,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -68,19 +62,6 @@ public final class RenderUtils {
return hitX >= aabb.minX && hitX <= aabb.maxX && hitY >= aabb.minY && hitY <= aabb.maxY && hitZ >= aabb.minZ && hitZ <= aabb.maxZ;
}
public static Vec3d getStart(EntityPlayer player) {
return new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
}
public static Vec3d getEnd(EntityPlayer player) {
double reachDistance = player instanceof EntityPlayerMP ? player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue() : (player.capabilities.isCreativeMode ? 5.0D : 4.5D);
Vec3d lookVec = player.getLookVec();
Vec3d start = getStart(player);
return start.addVector(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
}
public static String shorten(String text, int length) {
if (text.length() > length) {
text = text.substring(0, length) + "...";
@@ -88,42 +69,6 @@ public final class RenderUtils {
return text;
}
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<AxisAlignedBB> boxes) {
double minDistance = Double.POSITIVE_INFINITY;
AdvancedRayTraceResult hit = null;
int i = -1;
for (AxisAlignedBB aabb : boxes) {
AdvancedRayTraceResult result = aabb == null ? null : collisionRayTrace(pos, start, end, aabb, i, null);
if (result != null) {
double d = result.squareDistanceTo(start);
if (d < minDistance) {
minDistance = d;
hit = result;
}
}
i++;
}
return hit;
}
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, AxisAlignedBB bounds, int subHit, Object hitInfo) {
RayTraceResult result = bounds.offset(pos).calculateIntercept(start, end);
if (result == null) {
return null;
}
result = new RayTraceResult(RayTraceResult.Type.BLOCK, result.hitVec, result.sideHit, pos);
result.subHit = subHit;
result.hitInfo = hitInfo;
return new AdvancedRayTraceResult(result, bounds);
}
private static void setGLColorFromInt(int color) {
float red = (color >> 16 & 0xFF) / 255.0F;
float green = (color >> 8 & 0xFF) / 255.0F;
@@ -203,31 +148,6 @@ public final class RenderUtils {
return (int) multiplier;
}
private static class AdvancedRayTraceResultBase<T extends RayTraceResult> {
public final AxisAlignedBB bounds;
public final T hit;
public AdvancedRayTraceResultBase(T mop, AxisAlignedBB bounds) {
this.hit = mop;
this.bounds = bounds;
}
public boolean valid() {
return hit != null && bounds != null;
}
public double squareDistanceTo(Vec3d vec) {
return hit.hitVec.squareDistanceTo(vec);
}
}
public static class AdvancedRayTraceResult extends AdvancedRayTraceResultBase<RayTraceResult> {
public AdvancedRayTraceResult(RayTraceResult mop, AxisAlignedBB bounds) {
super(mop, bounds);
}
}
public static class FluidRenderer {
private static final int TEX_WIDTH = 16;
private static final int TEX_HEIGHT = 16;