Skip to content

Commit

Permalink
It fuckin works
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Nov 18, 2023
1 parent 0533046 commit d5c82af
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,59 +89,45 @@ public BlockState getPolymerBlockState(BlockState state) {
return getPolymerBlock(state).getDefaultState().with(LightBlock.LEVEL_15, 3);
}

@Override
public boolean tickElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
return true;
}

@Override
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
var tardisOptional = getTardis(world);
if (tardisOptional.isPresent()) {
var tardis = tardisOptional.get();
var rotation = RotationAxis.NEGATIVE_Y.rotationDegrees(initialBlockState.get(FACING).asRotation());

var stateText = new TextDisplayElement();
var destinationText = new TextDisplayElement();

stateText.setRightRotation(rotation);
destinationText.setRightRotation(rotation);
destinationText.setOffset(new Vec3d(0, -0.5, 0));

return new ElementHolder() {
{
addElement(stateText);
addElement(destinationText);
update();
}

@Override
protected void onTick() {
update();
}

private void update() {
stateText.setText(tardis.getState().getName());
destinationText.setText(Text.literal(tardis.getDestination()
.map(l -> l.pos().getX() + " " + l.pos().getY() + " " + l.pos().getZ() + " " + l.facing().getName().toUpperCase().charAt(0))
.orElse("Unknown"))); // TODO dimension
}
};
}
return null;
}
// @Override
// public boolean tickElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
// return true;
// }

// @Override
// public void onPolymerBlockSend(BlockState blockState, BlockPos.Mutable pos, ServerPlayerEntity player) {
// var main = new NbtCompound();
// main.putString("id", "minecraft:sign");
// main.putInt("x", pos.getX());
// main.putInt("y", pos.getY());
// main.putInt("z", pos.getZ());
// main.putBoolean("is_waxed", true);
// var frontText = new NbtCompound();
// var messages = new NbtList();
// messages.add()
// player.networkHandler.sendPacket(PolymerBlockUtils.createBlockEntityPacket(pos.toImmutable(), BlockEntityType.SIGN, main));
// @Override
// public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
// var tardisOptional = getTardis(world);
// if (tardisOptional.isPresent()) {
// var tardis = tardisOptional.get();
// var rotation = RotationAxis.NEGATIVE_Y.rotationDegrees(initialBlockState.get(FACING).asRotation());
//
// var stateText = new TextDisplayElement();
// var destinationText = new TextDisplayElement();
//
// stateText.setRightRotation(rotation);
// destinationText.setRightRotation(rotation);
// destinationText.setOffset(new Vec3d(0, -0.5, 0));
//
// return new ElementHolder() {
// {
// addElement(stateText);
// addElement(destinationText);
// update();
// }
//
// @Override
// protected void onTick() {
// update();
// }
//
// private void update() {
// stateText.setText(tardis.getState().getName());
// destinationText.setText(Text.literal(tardis.getDestination()
// .map(l -> l.pos().getX() + " " + l.pos().getY() + " " + l.pos().getZ() + " " + l.facing().getName().toUpperCase().charAt(0))
// .orElse("Unknown"))); // TODO dimension
// }
// };
// }
// return null;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2i;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -91,20 +92,26 @@ private void refresh(Tardis tardis) {
var canvas = display.getCanvas();
CanvasUtils.draw(canvas, 0, 0, ModCanvasUtils.SCREEN_BACKGROUND);
// DefaultFonts.VANILLA.drawText(canvas, "testlmao", 20, 16 + 20, 8, CanvasColor.WHITE_HIGH);
CanvasUtils.fill(display.getCanvas(), 64 + (int) getWorld().getTime() % 100 / 10, 64, 90, 90, CanvasColor.BLUE_NORMAL);
// CanvasUtils.fill(display.getCanvas(), 64 + (int) getWorld().getTime() % 100 / 10, 64, 90, 90, CanvasColor.BLUE_NORMAL);

for (int i = 0; i < DestinationScanner.TOTAL_BLOCKS; i++) {
byte value = tardis.getDestinationScanner().getForX(i);
var pos = DestinationScanner.getPos(i);
canvas.set(
pos.x + DestinationScanner.RANGE / 2, pos.y + DestinationScanner.RANGE / 2 + 16,
switch (value) {
case 0 -> CanvasColor.WHITE_HIGH;
case 1 -> CanvasColor.DEEPSLATE_GRAY_HIGH;
default -> CanvasColor.BLUE_NORMAL;
});
for (int x = 0; x < DestinationScanner.RANGE; x++) {
for (int y = 0; y < DestinationScanner.RANGE; y++) {
byte value = tardis.getDestinationScanner().getForX(x, y);
canvas.set(
x, -y + 15 + DestinationScanner.RANGE,
switch (value) {
case 0 -> CanvasColor.BLACK_HIGH;
case 1 -> CanvasColor.DEEPSLATE_GRAY_HIGH;
default -> CanvasColor.BLUE_NORMAL;
});
}
}

var destination = tardis.getDestination();
DefaultFonts.VANILLA.drawText(canvas,
"X: " + destination.map(l -> String.valueOf(l.pos().getX())).orElse("-"),
96 + 3, 16 + 3, 8, CanvasColor.WHITE_HIGH);

display.getCanvas().sendUpdates();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,33 @@ public void tick() {
@SuppressWarnings("OptionalGetWithoutIsPresent")
var location = tardis.getDestination().get();

xIterator = updateAxis(world, xAxis, xIterator, (pos3, pos2) -> pos3.move(location.pos()).move(pos2.x, pos2.y, 0));
xIterator = updateAxis(world, xAxis, xIterator, (pos3, pos2) -> pos3.set(location.pos()).move(pos2.x, pos2.y, 0));
});
}

public byte getForX(Vector2i pos) {
return getForX(getIndex(pos));
public byte getForX(int x, int y) {
return getForX(getIndex(x, y));
}

public byte getForX(int pos) {
return xAxis[pos];
}

public void resetIterators() {
xIterator = newIterator();
zIterator = newIterator();
}

private Iterator<Vector2i> updateAxis(ServerWorld world, byte[] axis, Iterator<Vector2i> iterator, BiConsumer<BlockPos.Mutable, Vector2i> posApplier) {
var pos3 = new BlockPos.Mutable();
var pos2 = new Vector2i();

for (int i = 0; i < maxPerTick; i++) {
if (!iterator.hasNext()) return newIterator();

var pos2 = iterator.next();
pos2.set(iterator.next());
posApplier.accept(pos3, pos2);
pos2.add(RANGE / 2 - 1, RANGE / 2 - 1);

var state = world.getBlockState(pos3);
byte value = (byte) (state.isReplaceable() ? 0 : state.isIn(ModBlocks.TARDIS_EXTERIOR_PARTS) ? 2 : 1);
Expand All @@ -59,7 +66,11 @@ private Iterator<Vector2i> updateAxis(ServerWorld world, byte[] axis, Iterator<V
}

public static int getIndex(Vector2i pos) {
return (pos.x + RANGE / 2) + (pos.y + RANGE / 2) * RANGE;
return getIndex(pos.x, pos.y);
}

public static int getIndex(int x, int y) {
return (x + y * RANGE) % TOTAL_BLOCKS;
}

public static Vector2i getPos(int index) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/enjarai/minitardis/component/Tardis.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void tick() {
state.playForInterior(this, ModSounds.CORAL_HUM, SoundCategory.AMBIENT, 0.3f, 1);
}

// destinationScanner.tick(); TODO ohno
destinationScanner.tick(); // TODO ohno
}

public ServerWorld getInteriorWorld() {
Expand Down Expand Up @@ -300,6 +300,7 @@ public boolean setDestination(Optional<TardisLocation> destination, boolean forc
if (!force && !state.canChangeCourse(this)) return false;

this.destination = destination;
destinationScanner.resetIterators();
return true;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5c82af

Please sign in to comment.