Skip to content

Commit

Permalink
texture namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Dec 9, 2024
1 parent 5664f5a commit 063f854
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class EveryCompat {
private static final List<CompatMod> COMPAT_MODS = new ArrayList<>();
// all mod that EC directly or indirectly depends on
private static final Set<String> DEPENDENCIES = new HashSet<>();
private static final Set<String> ADDON_IDS = new HashSet<>();

//these are the names of the block types we add wooden variants for
private static final Map<Class<? extends BlockType>, Set<String>> TYPES_TO_CHILD_KEYS = new Object2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -93,6 +94,7 @@ public static void addModule(CompatModule module) {
for (var t : module.getAffectedTypes()) {
addDynamicRegistrationFor(t);
}
ADDON_IDS.add(module.getMyNamespace());
}
}

Expand Down Expand Up @@ -189,6 +191,10 @@ protected static void registerEntities(Registrator<EntityType<?>> event) {
forAllModules(m -> m.registerEntities(event));
}

public static boolean isMyIdOrAddon(String namespace) {
return ADDON_IDS.contains(namespace);
}


public record CompatMod(String modId, List<String> woodsFrom, List<String> blocksFrom) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,23 +373,24 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha
ResourceLocation oldTextureId = re.getKey();
String oldPath = oldTextureId.getPath();

String newId = BlockTypeResTransformer.replaceTypeNoNamespace(oldPath, w,
String newPath = BlockTypeResTransformer.replaceTypeNoNamespace(oldPath, w,
blockId, baseType.get().getTypeName());
String newId = new ResourceLocation(blockId.getNamespace(), newPath).toString();

boolean isOnAtlas = true;

for (var info : infoPerTextures.get(oldTextureId)) {
if (info != null) {
if (info.keepNamespace()) {
newId = oldTextureId.withPath(newId).toString();
newId = oldTextureId.withPath(newPath).toString();
}
isOnAtlas = info.onAtlas();
}

Respriter respriter = re.getValue();

Supplier<TextureImage> textureSupplier = () -> respriter.recolorWithAnimation(finalTargetPalette, finalAnimation);
textureSupplier = addTexturePostProcessing(w, newId, manager, textureSupplier);
textureSupplier = postProcessTexture(w, newId, manager, textureSupplier);

handler.addTextureIfNotPresent(manager, newId, textureSupplier, isOnAtlas);
}
Expand All @@ -407,8 +408,8 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha
}

//post process some textures.
public Supplier<TextureImage> addTexturePostProcessing(T wood, String newId, ResourceManager manager,
Supplier<TextureImage> textureSupplier) {
public Supplier<TextureImage> postProcessTexture(T wood, String newId, ResourceManager manager,
Supplier<TextureImage> textureSupplier) {
if (wood.getClass() == WoodType.class) {
var changed = SpriteHelper.maybePostProcessWoodTexture((WoodType) wood, newId, manager, textureSupplier);
if (changed != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public void regenerateDynamicAssets(ResourceManager manager) {
m.addDynamicClientResources(this, manager);
} catch (Exception e) {
getLogger().error("Failed to generate client dynamic assets for module {}:", m, e);
if(PlatHelper.isDev()) throw e;
if (PlatHelper.isDev()) throw e;
}
});

ExtraTextureGenerator.generateExtraTextures(this, manager);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
@Mixin(BlockBehaviour.class)
public abstract class LootTablesHackMixin {

@Shadow public abstract Item asItem();
@Shadow
public abstract Item asItem();

@Inject(method = "getDrops", cancellable = true,
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/loot/LootTable;getRandomItems(Lnet/minecraft/world/level/storage/loot/LootParams;)Lit/unimi/dsi/fastutil/objects/ObjectArrayList;"
), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void addSimpleFastECdrops(BlockState state, LootParams.Builder builder, CallbackInfoReturnable<List<ItemStack>> cir, ResourceLocation resId,
LootParams lootParams, ServerLevel serverLevel, LootTable lootTable) {
if(lootTable == LootTable.EMPTY && Utils.getID(state.getBlock()).getNamespace().equals(EveryCompat.MOD_ID)){
if(SimpleEntrySet.isSimpleDrop(state.getBlock())){
if (lootTable == LootTable.EMPTY && EveryCompat.isMyIdOrAddon(Utils.getID(state.getBlock()).getNamespace())) {
if (SimpleEntrySet.isSimpleDrop(state.getBlock())) {
cir.setReturnValue(ECPlatStuff.modifyLoot(resId, List.of(this.asItem().getDefaultInstance()),
lootParams));
}
Expand Down

0 comments on commit 063f854

Please sign in to comment.