mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Fix belt lighting issues, again.
This commit is contained in:
parent
5eae3a53fc
commit
1233ecfe80
2 changed files with 64 additions and 40 deletions
|
@ -44,10 +44,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.util.math.Vec3i;
|
|
||||||
import net.minecraft.world.ILightReader;
|
import net.minecraft.world.ILightReader;
|
||||||
import net.minecraft.world.LightType;
|
import net.minecraft.world.LightType;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
@ -111,13 +108,15 @@ public class BeltTileEntity extends KineticTileEntity implements LightUpdateList
|
||||||
|
|
||||||
initializeItemHandler();
|
initializeItemHandler();
|
||||||
|
|
||||||
if (light == null && isController())
|
|
||||||
LightUpdater.getInstance().startListening(getBeltVolume(), this);
|
|
||||||
initializeLight();
|
|
||||||
|
|
||||||
// Move Items
|
// Move Items
|
||||||
if (!isController())
|
if (!isController())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (light == null && world.isRemote) {
|
||||||
|
initializeLight();
|
||||||
|
LightUpdater.getInstance().startListening(getBeltVolume(), this);
|
||||||
|
}
|
||||||
|
|
||||||
getInventory().tick();
|
getInventory().tick();
|
||||||
|
|
||||||
if (getSpeed() == 0)
|
if (getSpeed() == 0)
|
||||||
|
@ -530,54 +529,63 @@ public class BeltTileEntity extends KineticTileEntity implements LightUpdateList
|
||||||
GridAlignedBB beltVolume = getBeltVolume();
|
GridAlignedBB beltVolume = getBeltVolume();
|
||||||
|
|
||||||
if (beltVolume.intersects(changed)) {
|
if (beltVolume.intersects(changed)) {
|
||||||
GridAlignedBB section = changed.intersect(beltVolume);
|
|
||||||
|
|
||||||
if (type == LightType.BLOCK)
|
if (type == LightType.BLOCK)
|
||||||
section.forEachContained(this::updateBlockLight);
|
updateBlockLight();
|
||||||
|
|
||||||
if (type == LightType.SKY)
|
if (type == LightType.SKY)
|
||||||
section.forEachContained(this::updateSkyLight);
|
updateSkyLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GridAlignedBB getBeltVolume() {
|
private GridAlignedBB getBeltVolume() {
|
||||||
BlockPos endPos = controller.offset(getBeltFacing(), beltLength - 1);
|
BlockPos endPos = BeltHelper.getPositionForOffset(this, beltLength - 1);
|
||||||
|
|
||||||
return GridAlignedBB.from(pos, endPos);
|
GridAlignedBB bb = GridAlignedBB.from(pos, endPos);
|
||||||
}
|
bb.fixMinMax();
|
||||||
|
return bb;
|
||||||
private void updateBlockLight(int x, int y, int z) {
|
|
||||||
int segment = posToSegment(x, y, z) * 2;
|
|
||||||
|
|
||||||
light[segment] = (byte) world.getLightLevel(LightType.BLOCK, new BlockPos(x, y, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSkyLight(int x, int y, int z) {
|
|
||||||
int segment = posToSegment(x, y, z) * 2;
|
|
||||||
|
|
||||||
light[segment + 1] = (byte) world.getLightLevel(LightType.SKY, new BlockPos(x, y, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int posToSegment(int x, int y, int z) {
|
|
||||||
int dX = Math.abs(controller.getX() - x);
|
|
||||||
int dY = Math.abs(controller.getY() - y);
|
|
||||||
int dZ = Math.abs(controller.getZ() - z);
|
|
||||||
return dY + dX + dZ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeLight() {
|
private void initializeLight() {
|
||||||
light = new byte[beltLength * 2];
|
light = new byte[beltLength * 2];
|
||||||
|
|
||||||
Direction facing = getBeltFacing();
|
Vec3i vec = getBeltFacing().getDirectionVec();
|
||||||
BlockPos.Mutable pos = new BlockPos.Mutable(controller);
|
BeltSlope slope = getBlockState().get(BeltBlock.SLOPE);
|
||||||
for (int i = 0; i < beltLength; i++) {
|
int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0;
|
||||||
int segment = 2 * i;
|
|
||||||
light[segment] = (byte) world.getLightLevel(LightType.BLOCK, pos);
|
|
||||||
light[segment + 1] = (byte) world.getLightLevel(LightType.SKY, pos);
|
|
||||||
|
|
||||||
pos.move(facing);
|
BlockPos.Mutable pos = new BlockPos.Mutable(controller);
|
||||||
|
for (int i = 0; i < beltLength * 2; i += 2) {
|
||||||
|
light[i] = (byte) world.getLightLevel(LightType.BLOCK, pos);
|
||||||
|
light[i + 1] = (byte) world.getLightLevel(LightType.SKY, pos);
|
||||||
|
|
||||||
|
pos.move(vec.getX(), verticality, vec.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBlockLight() {
|
||||||
|
Vec3i vec = getBeltFacing().getDirectionVec();
|
||||||
|
BeltSlope slope = getBlockState().get(BeltBlock.SLOPE);
|
||||||
|
int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0;
|
||||||
|
|
||||||
|
BlockPos.Mutable pos = new BlockPos.Mutable(controller);
|
||||||
|
for (int i = 0; i < beltLength * 2; i += 2) {
|
||||||
|
light[i] = (byte) world.getLightLevel(LightType.BLOCK, pos);
|
||||||
|
|
||||||
|
pos.move(vec.getX(), verticality, vec.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSkyLight() {
|
||||||
|
Vec3i vec = getBeltFacing().getDirectionVec();
|
||||||
|
BeltSlope slope = getBlockState().get(BeltBlock.SLOPE);
|
||||||
|
int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0;
|
||||||
|
|
||||||
|
BlockPos.Mutable pos = new BlockPos.Mutable(controller);
|
||||||
|
for (int i = 1; i < beltLength * 2; i += 2) {
|
||||||
|
light[i] = (byte) world.getLightLevel(LightType.SKY, pos);
|
||||||
|
|
||||||
|
pos.move(vec.getX(), verticality, vec.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,22 @@ public class GridAlignedBB {
|
||||||
maxZ == other.maxZ;
|
maxZ == other.maxZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fixMinMax() {
|
||||||
|
int minX = Math.min(this.minX, this.maxX);
|
||||||
|
int minY = Math.min(this.minY, this.maxY);
|
||||||
|
int minZ = Math.min(this.minZ, this.maxZ);
|
||||||
|
int maxX = Math.max(this.minX, this.maxX);
|
||||||
|
int maxY = Math.max(this.minY, this.maxY);
|
||||||
|
int maxZ = Math.max(this.minZ, this.maxZ);
|
||||||
|
|
||||||
|
this.minX = minX;
|
||||||
|
this.minY = minY;
|
||||||
|
this.minZ = minZ;
|
||||||
|
this.maxX = maxX;
|
||||||
|
this.maxY = maxY;
|
||||||
|
this.maxZ = maxZ;
|
||||||
|
}
|
||||||
|
|
||||||
public int sizeX() {
|
public int sizeX() {
|
||||||
return maxX - minX;
|
return maxX - minX;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue