Skip to content

Commit b2a6f56

Browse files
committed
feat: allow use of external texture for i/o faces
1 parent 44b91b2 commit b2a6f56

File tree

63 files changed

+647
-1027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+647
-1027
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ plugins {
4747
id("fabric-loom") version("1.7-SNAPSHOT")
4848
id("org.cadixdev.licenser") version("0.6.1")
4949
id("org.ajoberstar.grgit") version("5.2.2")
50-
id("dev.galacticraft.mojarn") version("0.4.0+10")
50+
id("dev.galacticraft.mojarn") version("0.5.0+13")
5151
}
5252

5353
group = "dev.galacticraft"

gradle.properties

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ mod.version=0.7.0
77

88
# Minecraft and Fabric Loader
99
minecraft.version=1.21.1
10-
loader.version=0.15.11
10+
loader.version=0.16.5
1111
yarn.build=3
1212

1313
# Mod Dependencies
1414
badpackets.version=0.8.1
1515
energy.version=4.1.0
16-
fabric.version=0.102.1+1.21.1
16+
fabric.version=0.105.0+1.21.1
1717

1818
# Optional Mod Dependencies
19-
cloth.config.version=15.0.130
20-
modmenu.version=11.0.1
21-
rei.version=16.0.754
19+
cloth.config.version=15.0.140
20+
modmenu.version=11.0.2
21+
rei.version=16.0.777
2222
architectury.version=13.0.6
23-
wthit.version=12.3.0
23+
wthit.version=12.4.2

gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
3+
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME

src/main/java/dev/galacticraft/machinelib/api/block/MachineBlock.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
189189
super.setPlacedBy(level, pos, state, placer, itemStack);
190190
if (!level.isClientSide && placer instanceof ServerPlayer player) {
191191
if (level.getBlockEntity(pos) instanceof MachineBlockEntity machine) {
192-
machine.getSecurity().tryUpdate(player);
192+
machine.getSecurity().tryUpdate(player.getUUID());
193193
}
194194
}
195195
}
@@ -227,7 +227,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
227227
if (entity instanceof MachineBlockEntity machine) {
228228
SecuritySettings security = machine.getSecurity();
229229

230-
security.tryUpdate(player);
230+
security.tryUpdate(player.getUUID());
231231
if (security.hasAccess(player)) {
232232
return super.useWithoutItem(state, level, pos, player, hit);
233233
}

src/main/java/dev/galacticraft/machinelib/api/block/entity/ConfiguredBlockEntity.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
4343
import net.minecraft.server.level.ServerLevel;
4444
import net.minecraft.util.profiling.ProfilerFiller;
45-
import net.minecraft.world.entity.player.Player;
4645
import net.minecraft.world.level.block.Block;
4746
import net.minecraft.world.level.block.Blocks;
4847
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -51,6 +50,8 @@
5150
import org.jetbrains.annotations.NotNull;
5251
import org.jetbrains.annotations.Nullable;
5352

53+
import java.util.UUID;
54+
5455
public abstract class ConfiguredBlockEntity extends BaseBlockEntity implements RenderDataBlockEntity {
5556
private final @NotNull IOConfig configuration;
5657
private final @NotNull SecuritySettings security;
@@ -324,9 +325,9 @@ public void setPowered(boolean powered) {
324325
*/
325326
private class InternalSecuritySettings extends SecuritySettings {
326327
@Override
327-
public void tryUpdate(@NotNull Player player) {
328+
public void tryUpdate(@NotNull UUID uuid) {
328329
if (this.owner == null) {
329-
this.owner = player.getUUID();
330+
this.owner = uuid;
330331
ConfiguredBlockEntity.this.setChanged();
331332
}
332333
}

src/main/java/dev/galacticraft/machinelib/api/gametest/MachineGameTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ public TestFunction createDrainFluidIntoItemTest(int slot, Fluid fluid, int tank
167167
*/
168168
protected Machine createMachine(GameTestHelper helper) {
169169
helper.setBlock(MACHINE_POS, this.block);
170-
return (Machine) helper.getBlockEntity(MACHINE_POS);
170+
return helper.getBlockEntity(MACHINE_POS);
171171
}
172172
}

src/main/java/dev/galacticraft/machinelib/api/machine/configuration/SecuritySettings.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public class SecuritySettings implements Serializable<CompoundTag>, DeltaPacketS
5454
/**
5555
* Updates the owner of the linked machine if it is not already set.
5656
*
57-
* @param player the player to try to set as the owner
57+
* @param uuid the player to try to set as the owner
5858
*/
59-
public void tryUpdate(@NotNull Player player) {
59+
public void tryUpdate(@NotNull UUID uuid) {
6060
if (this.owner == null) {
61-
this.owner = player.getUUID();
61+
this.owner = uuid;
6262
}
6363
}
6464

src/main/java/dev/galacticraft/machinelib/api/menu/MenuData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
package dev.galacticraft.machinelib.api.menu;
2424

25-
import dev.architectury.utils.value.FloatSupplier;
2625
import dev.galacticraft.machinelib.api.misc.DeltaPacketSerializable;
26+
import dev.galacticraft.machinelib.api.util.FloatSupplier;
2727
import dev.galacticraft.machinelib.impl.menu.sync.*;
2828
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
2929
import it.unimi.dsi.fastutil.floats.FloatConsumer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021-2024 Team Galacticraft
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package dev.galacticraft.machinelib.api.util;
24+
25+
import java.util.function.Supplier;
26+
27+
/**
28+
* A {@link Supplier}, but for shorts
29+
* @see java.util.function.DoubleSupplier
30+
*/
31+
@FunctionalInterface
32+
public interface FloatSupplier extends Supplier<Float> {
33+
float getAsFloat();
34+
35+
@Override
36+
default Float get() {
37+
return this.getAsFloat();
38+
}
39+
}

src/main/java/dev/galacticraft/machinelib/client/api/model/MachineModelRegistry.java

+29-56
Original file line numberDiff line numberDiff line change
@@ -23,84 +23,57 @@
2323
package dev.galacticraft.machinelib.client.api.model;
2424

2525
import com.google.common.base.Preconditions;
26-
import com.google.gson.JsonObject;
27-
import dev.galacticraft.machinelib.api.machine.MachineRenderData;
28-
import dev.galacticraft.machinelib.api.util.BlockFace;
26+
import com.mojang.serialization.Codec;
27+
import dev.galacticraft.machinelib.client.api.model.sprite.MachineTextureBase;
28+
import dev.galacticraft.machinelib.client.api.model.sprite.SingleTextureProvider;
29+
import dev.galacticraft.machinelib.client.api.model.sprite.TextureProvider;
2930
import dev.galacticraft.machinelib.client.impl.model.MachineBakedModel;
30-
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
31-
import net.minecraft.client.resources.model.Material;
31+
import dev.galacticraft.machinelib.client.impl.model.MachineModelRegistryImpl;
3232
import net.minecraft.resources.ResourceLocation;
33-
import org.jetbrains.annotations.Contract;
3433
import org.jetbrains.annotations.NotNull;
3534
import org.jetbrains.annotations.Nullable;
3635

37-
import java.util.HashMap;
38-
import java.util.Map;
39-
import java.util.function.Function;
40-
4136
/**
4237
* A registry for {@link MachineBakedModel} sprite providers.
4338
*/
44-
public interface MachineModelRegistry {
45-
String MARKER = "machinelib:generate";
46-
Map<ResourceLocation, SpriteProviderFactory> FACTORIES = new HashMap<>();
39+
public final class MachineModelRegistry {
40+
public static final String MARKER = "machinelib:generate";
4741

4842
/**
4943
* Registers a sprite provider for a block.
5044
*
51-
* @param id The id to register the provider for.
52-
* @param factory The provider to register.
45+
* @param id the id to register the provider for
46+
* @param codec the provider to register
5347
*/
54-
static void register(@NotNull ResourceLocation id, @NotNull SpriteProviderFactory factory) {
48+
public static void register(@NotNull ResourceLocation id, @NotNull Codec<? extends TextureProvider<?>> codec) {
5549
Preconditions.checkNotNull(id);
56-
Preconditions.checkNotNull(factory);
50+
Preconditions.checkNotNull(codec);
5751

58-
FACTORIES.put(id, factory);
52+
MachineModelRegistryImpl.FACTORIES.put(id, codec);
53+
}
54+
55+
public static void registerBase(@NotNull ResourceLocation id, @NotNull MachineTextureBase bundle) {
56+
Preconditions.checkNotNull(id);
57+
Preconditions.checkNotNull(bundle);
58+
59+
MachineModelRegistryImpl.TEXTURE_BASES.put(id, bundle);
5960
}
6061

6162
/**
6263
* {@return the registered provider, or null if none is registered}
6364
*
64-
* @param providerId The provider id to get the provider for.
65+
* @param providerId the provider id to get the provider for
6566
*/
66-
static @Nullable SpriteProviderFactory getProviderFactory(@NotNull ResourceLocation providerId) {
67-
return FACTORIES.get(providerId);
68-
}
69-
70-
static @NotNull SpriteProviderFactory getProviderFactoryOrDefault(@NotNull ResourceLocation providerId) {
71-
return FACTORIES.getOrDefault(providerId, SpriteProviderFactory.DEFAULT);
67+
public static @Nullable Codec<? extends TextureProvider<?>> getProviderFactory(@NotNull ResourceLocation providerId) {
68+
return MachineModelRegistryImpl.FACTORIES.get(providerId);
7269
}
7370

74-
@FunctionalInterface
75-
interface SpriteProviderFactory {
76-
SpriteProviderFactory DEFAULT = new SpriteProviderFactory() {
77-
@Contract(value = "_, _ -> new", pure = true)
78-
@Override
79-
public @NotNull SpriteProvider create(@NotNull JsonObject json, @NotNull Function<Material, TextureAtlasSprite> atlas) {
80-
return new SpriteProvider() {
81-
private final TextureAtlasSprite machineSide = atlas.apply(MachineBakedModel.MACHINE_SIDE);
82-
private final TextureAtlasSprite machine = atlas.apply(MachineBakedModel.MACHINE);
83-
84-
@Override
85-
public @NotNull TextureAtlasSprite getSpritesForState(@Nullable MachineRenderData renderData, @NotNull BlockFace face) {
86-
if (face.side()) return this.machineSide;
87-
return this.machine;
88-
}
89-
};
90-
}
91-
};
92-
93-
SpriteProvider create(@NotNull JsonObject json, @NotNull Function<Material, TextureAtlasSprite> atlas);
94-
}
95-
96-
@FunctionalInterface
97-
interface SpriteProvider {
98-
/**
99-
* @param face The face that is being textured.
100-
* @return The appropriate sprite to render for the given face.
101-
*/
102-
@Contract(pure = true)
103-
@NotNull
104-
TextureAtlasSprite getSpritesForState(@Nullable MachineRenderData data, @NotNull BlockFace face);
71+
/**
72+
* {@return the registered provider, or {@link SingleTextureProvider#MISSING_CODEC} if none is registered}
73+
*
74+
* @param providerId the provider id to get the provider for
75+
*/
76+
public static @NotNull Codec<? extends TextureProvider<?>> getProviderFactoryOrDefault(@NotNull ResourceLocation providerId) {
77+
return MachineModelRegistryImpl.FACTORIES.getOrDefault(providerId, SingleTextureProvider.CODEC);
10578
}
10679
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2021-2024 Team Galacticraft
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package dev.galacticraft.machinelib.client.api.model.sprite;
24+
25+
import com.mojang.serialization.Codec;
26+
import com.mojang.serialization.codecs.RecordCodecBuilder;
27+
import dev.galacticraft.machinelib.api.machine.MachineRenderData;
28+
import dev.galacticraft.machinelib.api.util.BlockFace;
29+
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
30+
import net.minecraft.client.resources.model.Material;
31+
import org.jetbrains.annotations.NotNull;
32+
import org.jetbrains.annotations.Nullable;
33+
34+
import java.util.function.Function;
35+
36+
public record AxisSpriteProvider(Material front, Material back, Material base, Material side) implements TextureProvider<AxisSpriteProvider.Bound> {
37+
public static final Codec<AxisSpriteProvider> CODEC = RecordCodecBuilder.create(instance -> instance.group(
38+
MATERIAL_CODEC.fieldOf("front").forGetter(AxisSpriteProvider::front),
39+
MATERIAL_CODEC.fieldOf("back").forGetter(AxisSpriteProvider::back),
40+
MATERIAL_CODEC.fieldOf("base").forGetter(AxisSpriteProvider::base),
41+
MATERIAL_CODEC.fieldOf("side").forGetter(AxisSpriteProvider::side)
42+
).apply(instance, AxisSpriteProvider::new));
43+
44+
@Override
45+
public Bound bind(Function<Material, TextureAtlasSprite> atlas) {
46+
return new Bound(atlas.apply(this.front), atlas.apply(this.base), atlas.apply(this.side));
47+
}
48+
49+
public record Bound(TextureAtlasSprite front, TextureAtlasSprite base, TextureAtlasSprite side) implements BoundTextureProvider {
50+
@Override
51+
public TextureAtlasSprite getSprite(@Nullable MachineRenderData renderData, @NotNull BlockFace face) {
52+
if (face == BlockFace.FRONT) return this.front;
53+
if (face.side()) return this.side;
54+
return this.base;
55+
}
56+
57+
@Override
58+
public TextureAtlasSprite getParticle() {
59+
return this.base;
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)