Model parts
This commit is contained in:
parent
018a2ff545
commit
e31d58c6f5
5 changed files with 106 additions and 51 deletions
|
@ -21,7 +21,7 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
|
|||
|
||||
@Override
|
||||
public EntranceRiftBlockEntity getRift(World world, BlockPos pos, BlockState state) {
|
||||
return (EntranceRiftBlockEntity) this.createBlockEntity(world);
|
||||
return (EntranceRiftBlockEntity) world.getBlockEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package org.dimdev.dimdoors.block.entity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -44,7 +48,24 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
|
|||
}
|
||||
|
||||
public Direction getOrientation() {
|
||||
return Direction.NORTH;
|
||||
//noinspection ConstantConditions
|
||||
return Optional.of(this.world.getBlockState(this.pos))
|
||||
.filter(state -> state.contains(HorizontalFacingBlock.FACING))
|
||||
.map(state -> state.get(HorizontalFacingBlock.FACING))
|
||||
.orElse(Direction.NORTH);
|
||||
// BlockState state = this.world.getBlockState(this.pos);
|
||||
// if (state.contains(HorizontalFacingBlock.FACING)) {
|
||||
// return state.get(HorizontalFacingBlock.FACING);
|
||||
// }
|
||||
// return Direction.NORTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if the portal should be rendered two blocks tall
|
||||
*/
|
||||
public boolean isTall() {
|
||||
//noinspection ConstantConditions
|
||||
return this.world.getBlockState(this.pos).getBlock() instanceof DoorBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
|
@ -29,9 +30,12 @@ import net.fabricmc.api.Environment;
|
|||
@Environment(EnvType.CLIENT)
|
||||
public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<EntranceRiftBlockEntity> {
|
||||
private static final Random RANDOM = new Random(31100L);
|
||||
private final ModelPart warpModel;
|
||||
|
||||
public EntranceRiftBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
this.warpModel = new ModelPart(1024, 1024, 0, 0);
|
||||
this.warpModel.addCuboid(0, 0, 0, 16, 16, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +47,7 @@ public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<Entranc
|
|||
}
|
||||
Direction orientation = blockEntity.getOrientation();
|
||||
Vector3f vec = orientation.getOpposite().getUnitVector();
|
||||
this.renderVertices(blockEntity, matrices, vertexConsumers, orientation, vec, layers);
|
||||
this.renderVertices(blockEntity, matrices, vertexConsumers, orientation, vec, layers, light, overlay);
|
||||
|
||||
// Vec3d offset = new Vec3d(vec);
|
||||
// DimensionalPortalRenderer.renderDimensionalPortal(
|
||||
|
@ -61,16 +65,15 @@ public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<Entranc
|
|||
matrices.pop();
|
||||
}
|
||||
|
||||
private void renderVertices(EntranceRiftBlockEntity entrance, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Direction orientation, Vector3f vec, List<RenderLayer> layers) {
|
||||
private void renderVertices(EntranceRiftBlockEntity entrance, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Direction orientation, Vector3f vec, List<RenderLayer> layers, int light, int overlay) {
|
||||
vec.scale((float) (orientation == Direction.NORTH || orientation == Direction.WEST || orientation == Direction.UP ? 0.01 : 0.01 - 1));
|
||||
double squaredDistance = entrance.getPos().getSquaredDistance(this.dispatcher.camera.getPos(), true);
|
||||
int offset = this.getOffset(squaredDistance);
|
||||
float u = 0.75F;
|
||||
Matrix4f matrix4f = matrices.peek().getModel();
|
||||
this.drawAllVertices(entrance, u, 0.15F, matrix4f, vertexConsumers.getBuffer(layers.get(0)));
|
||||
this.drawAllVertices(entrance, u, 0.15F, matrices, vertexConsumers.getBuffer(layers.get(0)), light, overlay);
|
||||
|
||||
for (int i = 1; i < offset; ++i) {
|
||||
this.drawAllVertices(entrance, u, 2.0F / (float) (18 - i), matrix4f, vertexConsumers.getBuffer(layers.get(i)));
|
||||
this.drawAllVertices(entrance, u, 2.0F / (float) (18 - i), matrices, vertexConsumers.getBuffer(layers.get(i)), light, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,49 +97,57 @@ public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<Entranc
|
|||
}
|
||||
}
|
||||
|
||||
private void drawAllVertices(EntranceRiftBlockEntity blockEntity, float u, float v, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
|
||||
private void drawAllVertices(EntranceRiftBlockEntity blockEntity, float u, float v, MatrixStack matrices, VertexConsumer vertexConsumer, int light, int overlay) {
|
||||
float r = MathHelper.clamp((RANDOM.nextFloat() * 0.3F + 0.1F) * v, 0, 1);
|
||||
float g = MathHelper.clamp((RANDOM.nextFloat() * 0.4F + 0.1F) * v, 0, 1);
|
||||
float b = MathHelper.clamp((RANDOM.nextFloat() * 0.5F + 0.6F) * v, 0, 1);
|
||||
BlockState state = blockEntity.getCachedState();
|
||||
if (state.getBlock() instanceof DoorBlock) {
|
||||
Direction doorDir = state.get(HorizontalFacingBlock.FACING);
|
||||
switch (doorDir) {
|
||||
case NORTH:
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, r, g, b);
|
||||
break;
|
||||
case SOUTH:
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, r, g, b);
|
||||
break;
|
||||
case EAST:
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 1.0F, 0.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
break;
|
||||
case WEST:
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
} else {
|
||||
// South
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, r, g, b);
|
||||
// North
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F + 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, r, g, b);
|
||||
// East
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 1.0F, 1.0F, 1.0F + 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// West
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// Down
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, r, g, b);
|
||||
// Up
|
||||
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F + 1.0F, 1.0F + 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, r, g, b);
|
||||
this.warpModel.render(matrices, vertexConsumer, light, overlay, r, g, b, 1);
|
||||
if (blockEntity.isTall()) {
|
||||
matrices.push();
|
||||
matrices.translate(0, 1, 0);
|
||||
this.warpModel.render(matrices, vertexConsumer, light, overlay, r, g, b, 1);
|
||||
matrices.pop();
|
||||
}
|
||||
// Matrix4f matrix4f = matrices.peek().getModel();
|
||||
// BlockState state = blockEntity.getCachedState();
|
||||
// if (state.getBlock() instanceof DoorBlock) {
|
||||
// Direction doorDir = state.get(HorizontalFacingBlock.FACING);
|
||||
// switch (doorDir) {
|
||||
// case NORTH:
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, r, g, b);
|
||||
// break;
|
||||
// case SOUTH:
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, r, g, b);
|
||||
// break;
|
||||
// case EAST:
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 1.0F, 0.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// break;
|
||||
// case WEST:
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// break;
|
||||
// default:
|
||||
// throw new AssertionError();
|
||||
// }
|
||||
// } else {
|
||||
// // South
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F + 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, r, g, b);
|
||||
// // North
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F + 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, r, g, b);
|
||||
// // East
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 1.0F, 1.0F, 1.0F + 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// // West
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F + 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, r, g, b);
|
||||
// // Down
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, r, g, b);
|
||||
// // Up
|
||||
// this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F + 1.0F, 1.0F + 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, r, g, b);
|
||||
// }
|
||||
}
|
||||
|
||||
private void drawVertices(EntranceRiftBlockEntity endPortalBlockEntity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float x1, float x2, float y1, float y2, float z1, float z2, float z3, float z4, float red, float green, float blue) {
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, z1).color(red, green, blue, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, z2).color(red, green, blue, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, z3).color(red, green, blue, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, z4).color(red, green, blue, 1.0F).next();
|
||||
}
|
||||
// private void drawVertices(EntranceRiftBlockEntity endPortalBlockEntity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float x1, float x2, float y1, float y2, float z1, float z2, float z3, float z4, float red, float green, float blue) {
|
||||
// vertexConsumer.vertex(matrix4f, x1, y1, z1).color(red, green, blue, 1.0F).next();
|
||||
// vertexConsumer.vertex(matrix4f, x2, y1, z2).color(red, green, blue, 1.0F).next();
|
||||
// vertexConsumer.vertex(matrix4f, x2, y2, z3).color(red, green, blue, 1.0F).next();
|
||||
// vertexConsumer.vertex(matrix4f, x1, y2, z4).color(red, green, blue, 1.0F).next();
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.dimdev.dimdoors.rift.registry.RiftRegistry;
|
|||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.RGBA;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
|
||||
|
@ -40,7 +41,6 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg
|
|||
} else {
|
||||
EntityUtils.chat(entity, new TranslatableText("rifts.destinations.private_pocket_exit.rift_has_closed"));
|
||||
}
|
||||
//FabricDimensions.teleport(entity, entity.getServer().getWorld(ModDimensions.LIMBO));
|
||||
return false;
|
||||
} else {
|
||||
((EntityTarget) destLoc.getBlockEntity()).receiveEntity(entity, yawOffset);
|
||||
|
|
|
@ -36,4 +36,27 @@ public final class TeleportUtil {
|
|||
public static void teleport(ServerPlayerEntity player, RotatedLocation location) {
|
||||
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
|
||||
}
|
||||
|
||||
public static void teleportUntargeted(Entity entity, World world) {
|
||||
double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale();
|
||||
teleport(
|
||||
entity,
|
||||
world,
|
||||
entity.getPos().multiply(actualScale, 1, actualScale),
|
||||
entity.yaw
|
||||
);
|
||||
}
|
||||
|
||||
public static void teleportUntargeted(Entity entity, World world, double y) {
|
||||
double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale();
|
||||
teleport(
|
||||
entity,
|
||||
world,
|
||||
entity.getPos()
|
||||
.subtract(0, entity.getPos().getY(), 0)
|
||||
.add(0, y, 0)
|
||||
.multiply(actualScale, 1, actualScale),
|
||||
entity.yaw
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue