mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 21:53:41 +01:00
belt light
This commit is contained in:
parent
e690f2b8ac
commit
04ccf6e738
3 changed files with 32 additions and 45 deletions
|
@ -40,6 +40,10 @@ public class BeltHelper {
|
||||||
return getSegmentTE(world, controllerPos);
|
return getSegmentTE(world, controllerPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BeltTileEntity getBeltForOffset(BeltTileEntity controller, float offset) {
|
||||||
|
return getBeltAtSegment(controller, (int) Math.floor(offset));
|
||||||
|
}
|
||||||
|
|
||||||
public static BeltTileEntity getBeltAtSegment(BeltTileEntity controller, int segment) {
|
public static BeltTileEntity getBeltAtSegment(BeltTileEntity controller, int segment) {
|
||||||
BlockPos pos = getPositionForOffset(controller, segment);
|
BlockPos pos = getPositionForOffset(controller, segment);
|
||||||
TileEntity te = controller.getWorld()
|
TileEntity te = controller.getWorld()
|
||||||
|
|
|
@ -148,50 +148,6 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markForRebuild(InstanceContext<BeltTileEntity> ctx) {
|
|
||||||
BeltTileEntity te = ctx.te;
|
|
||||||
|
|
||||||
BlockState blockState = te.getBlockState();
|
|
||||||
if (!AllBlocks.BELT.has(blockState))
|
|
||||||
return;
|
|
||||||
|
|
||||||
BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE);
|
|
||||||
BeltPart part = blockState.get(BeltBlock.PART);
|
|
||||||
Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING);
|
|
||||||
AxisDirection axisDirection = facing.getAxisDirection();
|
|
||||||
|
|
||||||
boolean downward = beltSlope == BeltSlope.DOWNWARD;
|
|
||||||
boolean upward = beltSlope == BeltSlope.UPWARD;
|
|
||||||
boolean diagonal = downward || upward;
|
|
||||||
boolean start = part == BeltPart.START;
|
|
||||||
boolean end = part == BeltPart.END;
|
|
||||||
boolean sideways = beltSlope == BeltSlope.SIDEWAYS;
|
|
||||||
boolean vertical = beltSlope == BeltSlope.VERTICAL;
|
|
||||||
|
|
||||||
if (downward || vertical && axisDirection == AxisDirection.POSITIVE) {
|
|
||||||
boolean b = start;
|
|
||||||
start = end;
|
|
||||||
end = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (boolean bottom : Iterate.trueAndFalse) {
|
|
||||||
|
|
||||||
AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom);
|
|
||||||
|
|
||||||
InstancedModel<BeltData> beltBuffer = beltPartial.renderOnBelt(ctx, blockState);
|
|
||||||
|
|
||||||
beltBuffer.clearInstanceData();
|
|
||||||
|
|
||||||
// Diagonal belt do not have a separate bottom model
|
|
||||||
if (diagonal)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
InstancedModel<RotatingData> rotatingBuffer = getPulleyModel(ctx, blockState, sideways);
|
|
||||||
|
|
||||||
rotatingBuffer.clearInstanceData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private InstancedModel<RotatingData> getPulleyModel(InstanceContext<BeltTileEntity> ctx, BlockState blockState, boolean sideways) {
|
private InstancedModel<RotatingData> getPulleyModel(InstanceContext<BeltTileEntity> ctx, BlockState blockState, boolean sideways) {
|
||||||
Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING)
|
Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING)
|
||||||
.rotateY();
|
.rotateY();
|
||||||
|
@ -246,11 +202,14 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||||
float sideOffset = MathHelper.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
|
float sideOffset = MathHelper.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
|
||||||
float verticalMovement = verticality;
|
float verticalMovement = verticality;
|
||||||
|
|
||||||
|
|
||||||
if (te.getSpeed() == 0) {
|
if (te.getSpeed() == 0) {
|
||||||
offset = transported.beltPosition;
|
offset = transported.beltPosition;
|
||||||
sideOffset = transported.sideOffset;
|
sideOffset = transported.sideOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stackLight = getPackedLight(te, offset);
|
||||||
|
|
||||||
if (offset < .5)
|
if (offset < .5)
|
||||||
verticalMovement = 0;
|
verticalMovement = 0;
|
||||||
verticalMovement = verticalMovement * (Math.min(offset, te.beltLength - .5f) - .5f);
|
verticalMovement = verticalMovement * (Math.min(offset, te.beltLength - .5f) - .5f);
|
||||||
|
@ -318,7 +277,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ms.scale(.5f, .5f, .5f);
|
ms.scale(.5f, .5f, .5f);
|
||||||
itemRenderer.renderItem(transported.stack, TransformType.FIXED, light, overlay, ms, buffer);
|
itemRenderer.renderItem(transported.stack, TransformType.FIXED, stackLight, overlay, ms, buffer);
|
||||||
ms.pop();
|
ms.pop();
|
||||||
|
|
||||||
if (!renderUpright) {
|
if (!renderUpright) {
|
||||||
|
@ -335,4 +294,11 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||||
ms.pop();
|
ms.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getPackedLight(BeltTileEntity controller, float beltPos) {
|
||||||
|
BeltTileEntity belt = BeltHelper.getBeltForOffset(controller, beltPos);
|
||||||
|
|
||||||
|
if (belt == null) return 0;
|
||||||
|
|
||||||
|
return (belt.skyLight << 20) | (belt.blockLight << 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import net.minecraft.world.LightType;
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
import net.minecraftforge.client.model.data.IModelData;
|
||||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||||
import net.minecraftforge.client.model.data.ModelProperty;
|
import net.minecraftforge.client.model.data.ModelProperty;
|
||||||
|
@ -61,6 +62,10 @@ public class BeltTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
public CompoundNBT trackerUpdateTag;
|
public CompoundNBT trackerUpdateTag;
|
||||||
|
|
||||||
|
// client
|
||||||
|
public byte blockLight;
|
||||||
|
public byte skyLight;
|
||||||
|
|
||||||
public static enum CasingType {
|
public static enum CasingType {
|
||||||
NONE, ANDESITE, BRASS;
|
NONE, ANDESITE, BRASS;
|
||||||
}
|
}
|
||||||
|
@ -211,6 +216,7 @@ public class BeltTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
if (!clientPacket)
|
if (!clientPacket)
|
||||||
return;
|
return;
|
||||||
|
updateLight();
|
||||||
if (casingBefore == casing)
|
if (casingBefore == casing)
|
||||||
return;
|
return;
|
||||||
requestModelDataUpdate();
|
requestModelDataUpdate();
|
||||||
|
@ -465,4 +471,15 @@ public class BeltTileEntity extends KineticTileEntity {
|
||||||
return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing)
|
return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkLightUpdate() {
|
||||||
|
super.onChunkLightUpdate();
|
||||||
|
updateLight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLight() {
|
||||||
|
skyLight = (byte) world.getLightLevel(LightType.SKY, pos);
|
||||||
|
blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue