Skip to content

Commit

Permalink
Updated to BTA 7.3!
Browse files Browse the repository at this point in the history
Remade model assigment (should hopefully now be compatible with servers).
  • Loading branch information
MartinSVK12 committed Jan 28, 2025
1 parent 8fdb40d commit d33e70a
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 557 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ version = project.mod_version

loom {
noIntermediateMappings()
customMinecraftMetadata.set("https://github.com/Turnip-Labs/bta-manifest-repo/releases/download/v${project.bta_version}/${project.bta_version}.json")
customMinecraftMetadata.set("https://downloads.betterthanadventure.net/bta-client/${project.bta_channel}/v${project.bta_version}/manifest.json")
}

repositories {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
org.gradle.jvmargs=-Xmx2G

# BTA
bta_version=7.3-pre1
bta_channel=prerelease
bta_version=7.3
bta_channel=release

# Loader
loader_version=0.15.6-bta.7
Expand All @@ -11,6 +11,6 @@ loader_version=0.15.6-bta.7
mod_menu_version=3.0.0

# Mod
mod_version=5.0.0
mod_version=5.1.0
mod_group=turniplabs
mod_name=halplibe
25 changes: 0 additions & 25 deletions src/main/java/turniplabs/halplibe/HalpLibe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ public class HalpLibe implements ModInitializer, PreLaunchEntrypoint{
CONFIG = new TomlConfigHandler(MOD_ID, toml);
}

/*public static HashMap<String, Integer> itemKeyToIdMap = new HashMap<>();
public static int getTrueItemOrBlockId(String key){
// This all exists since the item key to id maps are somewhat unreliable due to blocks having their keys remapped after creation
if (itemKeyToIdMap.containsKey(key)) return itemKeyToIdMap.get(key);
if (key.startsWith("item")){
for (Item item : Item.itemsList){
if (item != null && item.getKey() != null && !item.getKey().isEmpty()){
itemKeyToIdMap.put(item.getKey(), item.id);
if (item.getKey().matches(key)) return item.id;
}
}
throw new IllegalArgumentException("Could not find an item that corresponds to the key '" + key + "'");
}
if (key.startsWith("tile")){
for (Block item : Block.blocksList){
if (item != null && item.getKey() != null && !item.getKey().isEmpty()){
itemKeyToIdMap.put(item.getKey(), item.id);
if (item.getKey().matches(key)) return item.id;
}
}
throw new IllegalArgumentException("Could not find a block that corresponds to the key '" + key + "'");
}
throw new IllegalArgumentException("Key '" + key + "' does not start with a valid predicate of 'item' or 'tile'");
}*/

@SuppressWarnings("unused")
@Deprecated
public static String addModId(String modId, String name) {
Expand Down
275 changes: 1 addition & 274 deletions src/main/java/turniplabs/halplibe/helper/BlockBuilder.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package turniplabs.halplibe.helper;

import net.minecraft.client.render.block.color.BlockColor;
import net.minecraft.client.render.block.color.BlockColorDispatcher;
import net.minecraft.client.render.block.model.BlockModel;
import net.minecraft.client.render.block.model.BlockModelDispatcher;
import net.minecraft.client.render.block.model.BlockModelStandard;
import net.minecraft.client.render.item.model.ItemModel;

import net.minecraft.client.render.item.model.ItemModelBlock;
import net.minecraft.client.render.item.model.ItemModelStandard;
import net.minecraft.core.block.Block;
Expand Down Expand Up @@ -52,9 +45,6 @@ public final class BlockBuilder implements Cloneable {
private boolean infiniburn = false;
private int @Nullable [] flammability = null;
private @Nullable BlockSound blockSound = null;
private @Nullable Function<Block<?>, BlockColor> blockColor = null;
private @NotNull Function<Block<?>, BlockModel<?>> blockModelSupplier = BlockModelStandard::new;
private @NotNull Function<ItemBlock<?>, ItemModel> customItemModelSupplier = ItemModelBlock::new;
private @Nullable BlockLambda<ItemBlock<?>> customBlockItem = null;
private @Nullable Tag<Block<?>>[] tags = null;
private String @NotNull [] textures = new String[6];
Expand All @@ -79,149 +69,6 @@ public BlockBuilder clone() {
}
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setTopTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.TOP.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setBottomTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.BOTTOM.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setNorthTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.NORTH.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setSouthTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.SOUTH.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setWestTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.WEST.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setEastTexture(String texture){
BlockBuilder builder = clone();
builder.textures[Side.EAST.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setTextures(String texture){
BlockBuilder builder = clone();
builder.textures[Side.TOP.getId()] = texture;
builder.textures[Side.BOTTOM.getId()] = texture;
builder.textures[Side.NORTH.getId()] = texture;
builder.textures[Side.SOUTH.getId()] = texture;
builder.textures[Side.WEST.getId()] = texture;
builder.textures[Side.EAST.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setSideTextures(String texture){
BlockBuilder builder = clone();
builder.textures[Side.NORTH.getId()] = texture;
builder.textures[Side.SOUTH.getId()] = texture;
builder.textures[Side.WEST.getId()] = texture;
builder.textures[Side.EAST.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setTopBottomTextures(String texture){
BlockBuilder builder = clone();
builder.textures[Side.TOP.getId()] = texture;
builder.textures[Side.BOTTOM.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setNorthSouthTextures(String texture){
BlockBuilder builder = clone();
builder.textures[Side.NORTH.getId()] = texture;
builder.textures[Side.SOUTH.getId()] = texture;
return builder;
}

/**
* Sets the texture on the side of the block model. Only applies if assigned block model extends {@link BlockModelStandard}
* @param texture Texture key
* @return Copy of the {@link BlockBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setEastWestTextures(String texture){
BlockBuilder builder = clone();
builder.textures[Side.WEST.getId()] = texture;
builder.textures[Side.EAST.getId()] = texture;
return builder;
}

/**
* Sets the block to be a TileEntity Block which creates the provided tile entities on placement
* @param tileEntitySupplier supplier of TileEntity instances for the block to create when placed
Expand All @@ -234,18 +81,6 @@ public BlockBuilder setTileEntity(@Nullable Supplier<TileEntity> tileEntitySuppl
return builder;
}

/**
* Sets the icon for the {@link Item}'s {@link ItemModel}, only works if the ItemModel used extends {@link ItemModelStandard} and the {@link BlockModel} renders as 2D
* @param iconKey texture key for the icon for the item to use. Example "minecraft:item/stick"
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings("unused")
public BlockBuilder setIcon(String iconKey){
BlockBuilder builder = clone();
builder.itemIcon = iconKey;
return builder;
}

/**
* Sets how long it takes to break the block.
*/
Expand Down Expand Up @@ -405,54 +240,6 @@ public BlockBuilder setBlockSound(BlockSound blockSound) {
return blockBuilder;
}

/**
* Makes the block's textures be colorized according to the provided BlockColor.<br>
* Example code:
* <pre>{@code
* public static final Block customGrassBlock = new BlockBuilder(MOD_ID)
* .setBlockColor(new BlockColorGrass())
* .build(new BlockGrass("custom.grass.block", 4001, Material.grass));
* }</pre>
*/
@SuppressWarnings({"unused"})
public BlockBuilder setBlockColor(Function<Block<?>, BlockColor> blockColorSupplier) {
BlockBuilder blockBuilder = this.clone();
blockBuilder.blockColor = blockColorSupplier;
return blockBuilder;
}

/**
* Sets the block's visible model.<br>
* Example code:
* <pre>{@code
* public static final Block customFlower = new BlockBuilder(MOD_ID)
* .setBlockModel(block -> new BlockModelCrossedSquares<>(block)))
* .build(new BlockFlower("custom.flower", 4002);
* }</pre>
*/
@SuppressWarnings({"unused"})
public BlockBuilder setBlockModel(@NotNull Function<Block<?>, BlockModel<?>> blockModelSupplier) {
BlockBuilder blockBuilder = this.clone();
blockBuilder.blockModelSupplier = blockModelSupplier;
return blockBuilder;
}

/**
* Sets the item form of the block's visible model.<br>
* Example code:
* <pre>{@code
* public static final Block customFlower = new BlockBuilder(MOD_ID)
* .setItemModel(block -> new ItemModelBlock(block, MOD_ID)))
* .build(new BlockFlower("custom.flower", 4002);
* }</pre>
*/
@SuppressWarnings({"unused"})
public BlockBuilder setItemModel(@NotNull Function<ItemBlock<?>, ItemModel> itemModelSupplier) {
BlockBuilder blockBuilder = this.clone();
blockBuilder.customItemModelSupplier = itemModelSupplier;
return blockBuilder;
}

/**
* Sets the block's item used to place the block.<br>
* Example code:
Expand Down Expand Up @@ -564,7 +351,7 @@ public <T extends BlockLogic> Block<T> build(String translationKey, String name,
block.withEntity(entitySupplier);
}

Assignment.queueBlockColor(block, blockColor);
//Assignment.queueBlockColor(block, blockColor);

if (tags != null) {
block.withTags(tags);
Expand All @@ -588,9 +375,6 @@ public <T extends BlockLogic> Block<T> build(String translationKey, String name,
BlocksAccessor.cacheBlock(block);
}

Assignment.queueBlockModel(block, blockModelSupplier, textures);
ItemBuilder.Assignment.queueItemModel(block.id(), customItemModelSupplier, itemIcon); // TODO reimpl item model

return block;
}

Expand Down Expand Up @@ -658,61 +442,4 @@ public static void reserveRuns(String modId, Toml runs, int neededIds, Consumer<
);
}
}
public static class Assignment{
public static boolean blockDispatcherInitialized = false;
public static final List<BlockAssignmentEntry<?>> queuedBlockModels = new ArrayList<>();

/**
* Queues a BlockModel assignment until the game is ready to do so
*/
public static <T extends Block<?>> void queueBlockModel(@NotNull T block, Function<T, BlockModel<?>> blockModelSupplier, @Nullable String[] textures){
if (!HalpLibe.isClient) return;
if (blockModelSupplier == null) return;

if (blockDispatcherInitialized){
BlockModelDispatcher.getInstance().addDispatch(new BlockAssignmentEntry<>(block, blockModelSupplier, textures).getModel());
return;
}
queuedBlockModels.add(new BlockAssignmentEntry<>(block, blockModelSupplier, textures));
}

public static class BlockAssignmentEntry<T extends Block<?>>{
public final T block;
public final Function<T, BlockModel<?>> modelFunction;
public final String[] textures;

public BlockAssignmentEntry(@NotNull T block, @NotNull Function<T, BlockModel<?>> modelFunction, @Nullable String[] textures){
this.block = block;
this.modelFunction = modelFunction;
this.textures = textures;
}
public BlockModel<?> getModel(){
BlockModel<?> model = modelFunction.apply(block);

if (model instanceof BlockModelStandard && textures != null){
for (int i = 0; i < textures.length; i++) {
if (textures[i] != null){
((BlockModelStandard<?>) model).setTex(BlockModelStandard.BLOCK_TEXTURES, textures[i], Side.getSideById(i));
}
}
}
return model;
}
}
public static boolean blockColorDispatcherInitialized = false;
public static final Map<Block<?>, Function<Block<?>, BlockColor>> queuedBlockColors = new LinkedHashMap<>();
/**
* Queues a BlockColor assignment until the game is ready to do so
*/
public static void queueBlockColor(@NotNull Block<?> block, Function<Block<?>, BlockColor> blockColorSupplier){
if (!HalpLibe.isClient) return;
if (blockColorSupplier == null) return;

if (blockColorDispatcherInitialized){
BlockColorDispatcher.getInstance().addDispatch(block, blockColorSupplier.apply(block));
return;
}
queuedBlockColors.put(block, blockColorSupplier);
}
}
}
Loading

0 comments on commit d33e70a

Please sign in to comment.