Skip to content

Commit

Permalink
Rewrite everything else in Java
Browse files Browse the repository at this point in the history
Removed support for old UUID format in trading station NBT.
  • Loading branch information
Juuxel committed Aug 2, 2024
1 parent 0add2f6 commit b045aec
Show file tree
Hide file tree
Showing 41 changed files with 677 additions and 661 deletions.
11 changes: 11 additions & 0 deletions common/src/main/java/juuxel/adorn/AdornCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package juuxel.adorn;

import net.minecraft.util.Identifier;

public final class AdornCommon {
public static final String NAMESPACE = "adorn";

public static Identifier id(String path) {
return new Identifier(NAMESPACE, path);
}
}
12 changes: 6 additions & 6 deletions common/src/main/java/juuxel/adorn/block/AdornBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import juuxel.adorn.lib.registry.RegistrarFactory;
import juuxel.adorn.lib.registry.RegistryHelper;
import juuxel.adorn.platform.PlatformBridges;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
Expand All @@ -29,7 +29,7 @@ public final class AdornBlocks {
public static final Registrar<Item> ITEMS = RegistrarFactory.get().create(RegistryKeys.ITEM);
private static final RegistryHelper HELPER = new RegistryHelper(BLOCKS, ITEMS);

public static final Registered<Map<DyeColor, SofaBlock>> SOFAS = ExtensionsKt.associateLazily(
public static final Registered<Map<DyeColor, SofaBlock>> SOFAS = AdornUtil.associateLazily(
DyeColor.values(),
color -> HELPER.registerBlock(
color.asString() + "_sofa",
Expand All @@ -54,7 +54,7 @@ public final class AdornBlocks {
public static final Registered<Block> SOULFUL_PRISMARINE_CHIMNEY = HELPER.registerBlock("soulful_prismarine_chimney",
() -> new PrismarineChimneyBlock.WithColumn(false, AbstractChimneyBlock.createBlockSettings(MapColor.CYAN, 1.5f)));

public static final Registered<Map<DyeColor, Block>> TABLE_LAMPS = ExtensionsKt.associateLazily(
public static final Registered<Map<DyeColor, Block>> TABLE_LAMPS = AdornUtil.associateLazily(
DyeColor.values(),
color -> HELPER.registerBlock(color.asString() + "_table_lamp", () -> new TableLampBlock(TableLampBlock.createBlockSettings(color)))
);
Expand All @@ -80,7 +80,7 @@ public final class AdornBlocks {
));

public static final Registered<Block> CRATE = HELPER.registerBlock("crate",
() -> new Block(ExtensionsKt.copySettingsSafely(Blocks.OAK_PLANKS)));
() -> new Block(AdornUtil.copySettingsSafely(Blocks.OAK_PLANKS)));
public static final Registered<Block> APPLE_CRATE = registerCrate("apple_crate");
public static final Registered<Block> WHEAT_CRATE = registerCrate("wheat_crate");
public static final Registered<Block> CARROT_CRATE = registerCrate("carrot_crate");
Expand Down Expand Up @@ -119,7 +119,7 @@ public final class AdornBlocks {

public static final Registered<Block> CANDLELIT_LANTERN = HELPER.registerBlock("candlelit_lantern",
() -> new CandlelitLanternBlock(CandlelitLanternBlock.createBlockSettings()));
public static final Registered<Map<DyeColor, Block>> DYED_CANDLELIT_LANTERNS = ExtensionsKt.associateLazily(
public static final Registered<Map<DyeColor, Block>> DYED_CANDLELIT_LANTERNS = AdornUtil.associateLazily(
DyeColor.values(),
color -> HELPER.registerBlock(
color.asString() + "_candlelit_lantern",
Expand Down Expand Up @@ -176,6 +176,6 @@ public static void init() {
}

private static Registered<Block> registerCrate(String name) {
return HELPER.registerBlock(name, () -> new Item.Settings().recipeRemainder(CRATE.get().asItem()), () -> new Block(ExtensionsKt.copySettingsSafely(CRATE.get())));
return HELPER.registerBlock(name, () -> new Item.Settings().recipeRemainder(CRATE.get().asItem()), () -> new Block(AdornUtil.copySettingsSafely(CRATE.get())));
}
}
10 changes: 5 additions & 5 deletions common/src/main/java/juuxel/adorn/block/BenchBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.lib.AdornStats;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import juuxel.adorn.util.Shapes;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -46,8 +46,8 @@ public final class BenchBlock extends SeatBlock implements Waterloggable, BlockW

for (var axis : new Direction.Axis[] { Direction.Axis.X, Direction.Axis.Z }) {
var topShape = axis == Direction.Axis.X ? X_TOP_SHAPE : Z_TOP_SHAPE;
var negativeLeg = legShapes.get(ExtensionsKt.getDirection(axis, Direction.AxisDirection.NEGATIVE));
var positiveLeg = legShapes.get(ExtensionsKt.getDirection(axis, Direction.AxisDirection.POSITIVE));
var negativeLeg = legShapes.get(Direction.from(axis, Direction.AxisDirection.NEGATIVE));
var positiveLeg = legShapes.get(Direction.from(axis, Direction.AxisDirection.POSITIVE));

for (var connectedN : booleans) {
for (var connectedP : booleans) {
Expand Down Expand Up @@ -80,7 +80,7 @@ public BenchBlock(BlockVariant variant) {
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
var state = getDefaultState()
.with(AXIS, ExtensionsKt.turnHorizontally(ctx.getHorizontalPlayerFacing().getAxis()))
.with(AXIS, AdornUtil.turnHorizontally(ctx.getHorizontalPlayerFacing().getAxis()))
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
return updateConnections(ctx.getWorld(), ctx.getBlockPos(), state);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public BlockState rotate(BlockState state, BlockRotation rotation) {
return switch (rotation) {
case COUNTERCLOCKWISE_90:
case CLOCKWISE_90:
yield state.with(AXIS, ExtensionsKt.turnHorizontally(state.get(AXIS)));
yield state.with(AXIS, AdornUtil.turnHorizontally(state.get(AXIS)));
default:
yield state;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import juuxel.adorn.criterion.AdornCriteria;
import juuxel.adorn.lib.AdornGameRules;
import juuxel.adorn.lib.AdornStats;
import juuxel.adorn.util.NbtExtensionsKt;
import juuxel.adorn.util.NbtUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void appendTooltip(ItemStack stack, @Nullable BlockView world, List<Text>

var nbt = stack.getSubNbt(BlockItem.BLOCK_ENTITY_TAG_KEY);
if (nbt != null && nbt.contains(TradingStationBlockEntity.NBT_TRADING_OWNER)) {
var owner = NbtExtensionsKt.getText(nbt, TradingStationBlockEntity.NBT_TRADING_OWNER_NAME);
var owner = NbtUtil.getText(nbt, TradingStationBlockEntity.NBT_TRADING_OWNER_NAME);
if (owner == null) owner = TradingStationBlockEntity.UNKNOWN_OWNER;
tooltip.add(Text.translatable(OWNER_DESCRIPTION, owner.copy().formatted(Formatting.WHITE)).formatted(Formatting.GREEN));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import juuxel.adorn.block.AdornBlockEntities;
import juuxel.adorn.menu.DrawerMenu;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.menu.Menu;
Expand All @@ -15,6 +15,6 @@ public DrawerBlockEntity(BlockPos pos, BlockState state) {

@Override
protected Menu createMenu(int syncId, PlayerInventory inv) {
return new DrawerMenu(syncId, inv, this, ExtensionsKt.menuContextOf(this));
return new DrawerMenu(syncId, inv, this, AdornUtil.menuContextOf(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import juuxel.adorn.block.AdornBlockEntities;
import juuxel.adorn.menu.KitchenCupboardMenu;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.menu.Menu;
Expand All @@ -15,6 +15,6 @@ public KitchenCupboardBlockEntity(BlockPos pos, BlockState state) {

@Override
protected Menu createMenu(int syncId, PlayerInventory inv) {
return new KitchenCupboardMenu(syncId, inv, this, ExtensionsKt.menuContextOf(this));
return new KitchenCupboardMenu(syncId, inv, this, AdornUtil.menuContextOf(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import juuxel.adorn.block.AdornBlockEntities;
import juuxel.adorn.menu.TradingStationMenu;
import juuxel.adorn.trading.Trade;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import juuxel.adorn.util.InventoryComponent;
import juuxel.adorn.util.NbtExtensionsKt;
import juuxel.adorn.util.NbtUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean isOwner(PlayerEntity player) {

@Override
public Menu createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return new TradingStationMenu(syncId, playerInventory, ExtensionsKt.menuContextOf(this));
return new TradingStationMenu(syncId, playerInventory, AdornUtil.menuContextOf(this));
}

@Override
Expand Down Expand Up @@ -102,11 +102,9 @@ public void readNbt(NbtCompound nbt) {

if (nbt.containsUuid(NBT_TRADING_OWNER)) {
owner = nbt.getUuid(NBT_TRADING_OWNER);
} else if (NbtExtensionsKt.containsOldUuid(nbt, NBT_TRADING_OWNER)) {
owner = NbtExtensionsKt.getOldUuid(nbt, NBT_TRADING_OWNER);
}

ownerName = Objects.requireNonNullElse(NbtExtensionsKt.getText(nbt, NBT_TRADING_OWNER_NAME), UNKNOWN_OWNER);
ownerName = Objects.requireNonNullElse(NbtUtil.getText(nbt, NBT_TRADING_OWNER_NAME), UNKNOWN_OWNER);
trade.readNbt(nbt.getCompound(NBT_TRADE));
storage.readNbt(nbt.getCompound(NBT_STORAGE));
}
Expand All @@ -119,7 +117,7 @@ protected void writeNbt(NbtCompound nbt) {
nbt.putUuid(NBT_TRADING_OWNER, owner);
}

NbtExtensionsKt.putText(nbt, NBT_TRADING_OWNER_NAME, ownerName);
NbtUtil.putText(nbt, NBT_TRADING_OWNER_NAME, ownerName);

nbt.put(NBT_TRADE, trade.writeNbt(new NbtCompound()));
nbt.put(NBT_STORAGE, storage.writeNbt(new NbtCompound()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package juuxel.adorn.block.variant;

import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -102,7 +102,7 @@ public String name() {

@Override
public AbstractBlock.Settings createSettings() {
return ExtensionsKt.copySettingsSafely(base);
return AdornUtil.copySettingsSafely(base);
}
};
}
Expand All @@ -114,14 +114,14 @@ static BlockVariant wool(DyeColor color) {
record Wood(String name) implements BlockVariant {
@Override
public AbstractBlock.Settings createSettings() {
return ExtensionsKt.copySettingsSafely(Blocks.OAK_PLANKS);
return AdornUtil.copySettingsSafely(Blocks.OAK_PLANKS);
}
}

record Stone(String name) implements BlockVariant {
@Override
public AbstractBlock.Settings createSettings() {
return ExtensionsKt.copySettingsSafely(Blocks.COBBLESTONE);
return AdornUtil.copySettingsSafely(Blocks.COBBLESTONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import juuxel.adorn.fluid.FluidReference;
import juuxel.adorn.fluid.FluidVolume;
import juuxel.adorn.menu.BrewerMenu;
import juuxel.adorn.util.ColorsKt;
import juuxel.adorn.util.Colors;
import juuxel.adorn.util.Logging;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void drawFluid(DrawContext context, int x, int y, FluidReference f
return;
}

var color = ColorsKt.color(bridge.getColor(fluid));
var color = Colors.color(bridge.getColor(fluid));
var height = FLUID_AREA_HEIGHT * (float) (fluid.getAmount() / (BrewerBlockEntity.FLUID_CAPACITY_IN_BUCKETS * fluid.getUnit().getBucketVolume()));
var fluidY = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import juuxel.adorn.client.gui.widget.ScrollEnvelope;
import juuxel.adorn.client.gui.widget.SizedElement;
import juuxel.adorn.client.gui.widget.TickingElement;
import juuxel.adorn.util.CollectionsKt;
import juuxel.adorn.util.CollectionUtil;
import juuxel.adorn.util.Colors;
import juuxel.adorn.util.animation.AnimationEngine;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -207,7 +207,7 @@ private BookPageTitle(int x, int y, Page page) {
this.x = x;
this.y = y;
this.wrappedTitleLines = textRenderer.wrapLines(page.title().copy().styled(style -> style.withBold(true)), PAGE_TITLE_WIDTH);
this.icons = CollectionsKt.interleave(page.icons().stream().map(Page.Icon::createStacks).toList());
this.icons = CollectionUtil.interleave(page.icons().stream().map(Page.Icon::createStacks).toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package juuxel.adorn.client.gui.widget;

import juuxel.adorn.util.Colors;
import juuxel.adorn.util.ColorsKt;
import juuxel.adorn.util.animation.AnimatedProperty;
import juuxel.adorn.util.animation.AnimatedPropertyWrapper;
import juuxel.adorn.util.animation.AnimationEngine;
Expand All @@ -15,11 +14,11 @@ public final class ScrollEnvelope extends ScissorEnvelope {
private static final double SHADOW_THRESHOLD = 1.0;
private static final int GRADIENT_HEIGHT = 5;
private static final int SCROLLING_SPEED = 20;
private static final int GRADIENT_COLOR = ColorsKt.color(0x000000, 0.2f);
private static final int GRADIENT_COLOR = Colors.color(0x000000, 0.2f);
private static final int SCROLLING_TRACK_MARGIN = 2;
private static final int SCROLLING_TRACK_WIDTH = 4;
private static final int SCROLL_THUMB_COLOR_INACTIVE = ColorsKt.color(0x000000, 0.2f);
private static final int SCROLL_THUMB_COLOR_ACTIVE = ColorsKt.color(0x000000, 0.6f);
private static final int SCROLL_THUMB_COLOR_INACTIVE = Colors.color(0x000000, 0.2f);
private static final int SCROLL_THUMB_COLOR_ACTIVE = Colors.color(0x000000, 0.6f);

private final SizedElement element;
private double offset = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import juuxel.adorn.block.entity.TradingStationBlockEntity;
import juuxel.adorn.config.ConfigManager;
import juuxel.adorn.util.Colors;
import juuxel.adorn.util.ColorsKt;
import juuxel.adorn.util.ExtensionsKt;
import juuxel.adorn.util.AdornUtil;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
Expand Down Expand Up @@ -56,8 +55,8 @@ public void render(TradingStationBlockEntity be, float tickDelta, MatrixStack ma
Text label1 = Text.translatable(OWNER_LABEL, be.getOwnerName().copy().formatted(Formatting.GOLD));
renderLabel(be, label1, 0.0, 0.9, 0.0, 12, matrices, vertexConsumers, light);
if (!be.getTrade().isEmpty()) {
Text label2 = Text.translatable(SELLING_LABEL, ExtensionsKt.toTextWithCount(be.getTrade().getSelling()));
Text label3 = Text.translatable(PRICE_LABEL, ExtensionsKt.toTextWithCount(be.getTrade().getPrice()));
Text label2 = Text.translatable(SELLING_LABEL, AdornUtil.toTextWithCount(be.getTrade().getSelling()));
Text label3 = Text.translatable(PRICE_LABEL, AdornUtil.toTextWithCount(be.getTrade().getPrice()));
renderLabel(be, label2, 0.0, 0.9 - 0.25, 0.0, 12, matrices, vertexConsumers, light);
renderLabel(be, label3, 0.0, 0.9 - 0.5, 0.0, 12, matrices, vertexConsumers, light);
}
Expand All @@ -79,7 +78,7 @@ private void renderLabel(

var positionMatrix = matrices.peek().getPositionMatrix();
float opacity = MinecraftClient.getInstance().options.getTextBackgroundOpacity(0.25f);
int backgroundColor = ColorsKt.color(0x000000, opacity);
int backgroundColor = Colors.color(0x000000, opacity);
var textX = -textRenderer.getWidth(label) * 0.5f;
textRenderer.draw(label, textX, 0f, Colors.WHITE, false, positionMatrix, vertexConsumers, TextRenderer.TextLayerType.NORMAL, backgroundColor, light);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import juuxel.adorn.AdornCommon;
import juuxel.adorn.util.Colors;
import juuxel.adorn.util.ColorsKt;
import juuxel.adorn.util.Logging;
import net.minecraft.resource.ResourceFinder;
import net.minecraft.resource.ResourceManager;
Expand Down Expand Up @@ -98,7 +97,7 @@ private static DataResult<Integer> parseHexColor(String str) {

var colorStr = str.substring(1);
return DataResult.success(switch (colorStr.length()) {
case 6 -> ColorsKt.color(Integer.parseInt(colorStr, 16));
case 6 -> Colors.color(Integer.parseInt(colorStr, 16));
case 8 -> Integer.parseInt(colorStr, 16);
default -> throw new MatchException("Mismatching color length: " + colorStr.length(), null);
});
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/juuxel/adorn/entity/SeatEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import juuxel.adorn.block.SeatBlock;
import juuxel.adorn.platform.PlatformBridges;
import juuxel.adorn.util.NbtExtensionsKt;
import juuxel.adorn.util.NbtUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
Expand Down Expand Up @@ -85,12 +85,12 @@ protected void initDataTracker() {

@Override
protected void readCustomDataFromNbt(NbtCompound nbt) {
seatPos = NbtExtensionsKt.getBlockPos(nbt, NBT_SEAT_POS);
seatPos = NbtUtil.getBlockPos(nbt, NBT_SEAT_POS);
}

@Override
protected void writeCustomDataToNbt(NbtCompound nbt) {
NbtExtensionsKt.putBlockPos(nbt, NBT_SEAT_POS, seatPos);
NbtUtil.putBlockPos(nbt, NBT_SEAT_POS, seatPos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import juuxel.adorn.block.entity.TradingStationBlockEntity;
import juuxel.adorn.trading.Trade;
import juuxel.adorn.util.NbtExtensionsKt;
import juuxel.adorn.util.NbtUtil;
import net.minecraft.block.Block;
import net.minecraft.client.item.TooltipData;
import net.minecraft.item.ItemStack;
Expand All @@ -24,7 +24,7 @@ public boolean canBeNested() {
public Optional<TooltipData> getTooltipData(ItemStack stack) {
var nbt = stack.getSubNbt(BLOCK_ENTITY_TAG_KEY);
if (nbt != null) {
var tradeNbt = NbtExtensionsKt.getCompoundOrNull(nbt, TradingStationBlockEntity.NBT_TRADE);
var tradeNbt = NbtUtil.getCompoundOrNull(nbt, TradingStationBlockEntity.NBT_TRADE);
if (tradeNbt != null) {
var trade = Trade.fromNbt(tradeNbt);
if (!trade.isFullyEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/juuxel/adorn/item/WateringCanItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import juuxel.adorn.fluid.StepMaximum;
import juuxel.adorn.lib.AdornSounds;
import juuxel.adorn.platform.FluidBridge;
import juuxel.adorn.util.ColorsKt;
import juuxel.adorn.util.Colors;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FarmlandBlock;
Expand Down Expand Up @@ -188,7 +188,7 @@ public int getItemBarColor(ItemStack stack) {
// To:
0.4f, 1f
);
return ColorsKt.color(rg, rg, 1f);
return Colors.color(rg, rg, 1f);
}

@Override
Expand Down
Loading

0 comments on commit b045aec

Please sign in to comment.