Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

帮助拉取上游更新避免出错 #82

Merged
merged 6 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 89 additions & 18 deletions processor/src/main/java/org/polaris2023/utils/Codes.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public final class %%classname%% implements DataProvider, IModel<%%classname%%>
private Path assetsDir;
private final ConcurrentHashMap<ResourceLocation, Object> MODELS =
new ConcurrentHashMap<>();// object is Bean or map, by gson

private final ConcurrentHashMap<ResourceLocation, Object> BLOCKSTATES =
new ConcurrentHashMap<>();
private <T extends Item> %%classname%% basicItem(Supplier<T> item) {
ResourceLocation key = BuiltInRegistries.ITEM.getKey(item.get()).withPrefix("item/");
MODELS.put(key, Map.of("parent", "minecraft:item/generated", "textures", Map.of(
Expand Down Expand Up @@ -104,39 +105,101 @@ public final class %%classname%% implements DataProvider, IModel<%%classname%%>
}

private <T extends Block> %%classname%% cubeAll(Supplier<T> block) {
ResourceLocation key = BuiltInRegistries.BLOCK.getKey(block.get()).withPrefix("block/");
MODELS.put(key, Map.of(
ResourceLocation key = BuiltInRegistries.BLOCK.getKey(block.get());
ResourceLocation blockKey = key.withPrefix("block/");
MODELS.put(blockKey, Map.of(
"parent", "minecraft:block/cube_all",
"textures", Map.of(
"all", key.toString()
"all", blockKey.toString()
)
));
BLOCKSTATES.put(key, Map.of(
"variants", Map.of(
"", Map.of(
"model", blockKey.toString()
)
)
));
return this;
}

private <T extends Block> %%classname%% stairsBlock(Supplier<T> block, String bottom, String side, String top) {
ResourceLocation key = BuiltInRegistries.BLOCK.getKey(block.get()).withPrefix("block/");
MODELS.put(key, Map.of(
ResourceLocation key = BuiltInRegistries.BLOCK.getKey(block.get());
ResourceLocation blockKey = key.withPrefix("block/");
ResourceLocation inner = blockKey.withSuffix("_inner");
ResourceLocation outer = blockKey.withSuffix("_outer");
MODELS.put(blockKey, Map.of(
"parent", "minecraft:block/stairs",
"textures", Map.of(
"bottom", bottom.isEmpty() ? key.toString() : bottom,
"side", side.isEmpty() ? key.toString() : side,
"top", top.isEmpty() ? key.toString() : top
"bottom", bottom.isEmpty() ? blockKey.toString() : bottom,
"side", side.isEmpty() ? blockKey.toString() : side,
"top", top.isEmpty() ? blockKey.toString() : top
)));
MODELS.put(key.withSuffix("_inner"), Map.of(
MODELS.put(inner, Map.of(
"parent", "minecraft:block/inner_stairs",
"textures", Map.of(
"bottom", bottom.isEmpty() ? key.toString() : bottom,
"side", side.isEmpty() ? key.toString() : side,
"top", top.isEmpty() ? key.toString() : top
"bottom", bottom.isEmpty() ? blockKey.toString() : bottom,
"side", side.isEmpty() ? blockKey.toString() : side,
"top", top.isEmpty() ? blockKey.toString() : top
)));
MODELS.put(key.withSuffix("_outer"), Map.of(
MODELS.put(outer, Map.of(
"parent", "minecraft:block/outer_stairs",
"textures", Map.of(
"bottom", bottom.isEmpty() ? key.toString() : bottom,
"side", side.isEmpty() ? key.toString() : side,
"top", top.isEmpty() ? key.toString() : top
"bottom", bottom.isEmpty() ? blockKey.toString() : bottom,
"side", side.isEmpty() ? blockKey.toString() : side,
"top", top.isEmpty() ? blockKey.toString() : top
)));
BLOCKSTATES.put(key, Map.of(
"variants", Map.of(
"facing=east,half=bottom,shape=inner_left", Map.of(
"model", inner.toString(),
"uvlock", true,
"y", 270
),
"facing=east,half=bottom,shape=inner_right", Map.of(
"model", inner.toString()
),
"facing=east,half=bottom,shape=outer_left", Map.of(
"model", outer.toString(),
"uvlock", true,
"y", 270
),
"facing=east,half=bottom,shape=outer_right", Map.of(
"model", outer.toString()
),
"facing=east,half=bottom,shape=straight", Map.of(
"model", blockKey.toString()
),
"facing=east,half= top,shape=inner_left", Map.of(
"model", inner.toString(),
"uvlock", true,
"x", 180
),
"facing=east,half=top,shape=inner_right", Map.of(
"model", inner.toString(),
"uvlock", true,
"x", 180,
"y", 90
),
"facing=east,half=top,shape=outer_left", Map.of(
"model", outer.toString(),
"uvlock", true,
"z", 180
),
"facing=east,half=top,shape=outer_right", Map.of(
"model", outer.toString(),
"uvlock", true,
"x", 180,
"y", 90

),
"facing=east,half= top,shape=straight", Map.of(
"model", blockKey.toString(),
"uvlock", true,
"x", 180
)
)
));
return this;
}

Expand Down Expand Up @@ -212,7 +275,7 @@ public void init() {
@Override
public CompletableFuture<?> run(CachedOutput output) {
init();
CompletableFuture<?>[] futures = new CompletableFuture[MODELS.size()];
CompletableFuture<?>[] futures = new CompletableFuture[MODELS.size() + BLOCKSTATES.size()];
int i = 0;
for (Map.Entry<ResourceLocation, Object> entry : MODELS.entrySet()) {
ResourceLocation key = entry.getKey();
Expand All @@ -222,6 +285,14 @@ public CompletableFuture<?> run(CachedOutput output) {
futures[i] = DataProvider.saveStable(output, jsonTree, itemModel);
i++;
}
for(Map.Entry<ResourceLocation, Object> entry : BLOCKSTATES.entrySet()) {
ResourceLocation key = entry.getKey();
Object object = entry.getValue();
Path states = assetsDir.resolve(key.getNamespace()).resolve("blockstates").resolve(key.getPath() + ".json");
JsonElement jsonTree = GSON.toJsonTree(object);
futures[i] = DataProvider.saveStable(output, jsonTree, states);
i++;
}
return CompletableFuture.allOf(futures);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package org.polaris2023.wild_wind.client;

import net.minecraft.client.color.block.BlockColor;
import net.minecraft.core.BlockPos;
import net.minecraft.util.FastColor;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import org.jetbrains.annotations.Nullable;
import org.polaris2023.wild_wind.client.entity.abstracts.ModMobRenderer;
import org.polaris2023.wild_wind.client.entity.firefly.FireflyModel;
import org.polaris2023.wild_wind.client.entity.piranha.PiranhaModel;
import org.polaris2023.wild_wind.client.entity.trout.TroutModel;
import org.polaris2023.wild_wind.common.block.WoolBlock;
import org.polaris2023.wild_wind.common.block.entity.WoolBlockEntity;
import org.polaris2023.wild_wind.common.init.ModBlocks;
import org.polaris2023.wild_wind.common.init.ModComponents;
import org.polaris2023.wild_wind.common.init.ModEntities;
Expand All @@ -38,14 +29,7 @@ public static void registerSlimeColor(RegisterColorHandlersEvent.Item event) {

@SubscribeEvent
public static void registerBlockColor(RegisterColorHandlersEvent.Block event) {
event.register((state, level, pos, tinIndex) -> {
if (level == null || pos == null) {
return FastColor.ARGB32.opaque(0);
}
WoolBlockEntity woolTile = (WoolBlockEntity) level.getBlockEntity(pos);
if (woolTile == null) return FastColor.ARGB32.opaque(0);
return FastColor.ARGB32.opaque(woolTile.rgb);
}, ModBlocks.WOOL.get());

}

@SubscribeEvent
Expand Down
Loading
Loading