-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start BlockState Json File Redirections Work
- Loading branch information
1 parent
3f4e495
commit 5364732
Showing
11 changed files
with
213 additions
and
28 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/fr/firstmegagame4/env/driven/assets/client/blockstate/BlockStateManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.firstmegagame4.env.driven.assets.client.blockstate; | ||
|
||
import fr.firstmegagame4.env.json.api.EnvJson; | ||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.block.BlockModels; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class BlockStateManager { | ||
|
||
public final Map<Block, EnvJson> envJsonBlocks = new Object2ObjectOpenHashMap<>(); | ||
|
||
public final Map<Identifier, BlockStateModelProvider> modelProviders = new Object2ObjectOpenHashMap<>(); | ||
|
||
public EnvJson getStateEnvJson(BlockState state) { | ||
return this.envJsonBlocks.get(state.getBlock()); | ||
} | ||
|
||
public BlockStateModelProvider getProvider(Identifier identifier) { | ||
return this.modelProviders.get(identifier); | ||
} | ||
|
||
public void appendBlock(Block block, EnvJson envJson) { | ||
this.envJsonBlocks.put(block, envJson); | ||
} | ||
|
||
public void provideIdentifiers(Block block, Function<Map<BlockState, ModelIdentifier>, Map<BlockState, BakedModel>> baker) { | ||
if (this.envJsonBlocks.containsKey(block)) { | ||
EnvJson envJson = this.envJsonBlocks.get(block); | ||
envJson.members().forEach(member -> { | ||
BlockStateModelProvider.Builder builder = new BlockStateModelProvider.Builder(); | ||
Map<BlockState, ModelIdentifier> map = new Object2ObjectOpenHashMap<>(); | ||
block.getStateManager().getStates().forEach(state -> map.put(state, BlockModels.getModelId(member.result(), state))); | ||
builder.append(baker.apply(map)); | ||
this.modelProviders.put(member.result(), builder.build()); | ||
}); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...n/java/fr/firstmegagame4/env/driven/assets/client/blockstate/BlockStateModelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fr.firstmegagame4.env.driven.assets.client.blockstate; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
|
||
import java.util.Map; | ||
|
||
public class BlockStateModelProvider { | ||
|
||
private final Map<BlockState, BakedModel> provider = new Object2ObjectOpenHashMap<>(); | ||
|
||
private BlockStateModelProvider() {} | ||
|
||
public BakedModel apply(BlockState state) { | ||
return this.provider.get(state); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private final Map<BlockState, BakedModel> elements = new Object2ObjectOpenHashMap<>(); | ||
|
||
public Builder append(BlockState state, BakedModel model) { | ||
this.elements.put(state, model); | ||
return this; | ||
} | ||
|
||
public Builder append(Map<BlockState, BakedModel> elements) { | ||
this.elements.putAll(elements); | ||
return this; | ||
} | ||
|
||
public BlockStateModelProvider build() { | ||
BlockStateModelProvider provider = new BlockStateModelProvider(); | ||
provider.provider.putAll(this.elements); | ||
return provider; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/fr/firstmegagame4/env/driven/assets/client/duck/JsonObjectDuckInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fr.firstmegagame4.env.driven.assets.client.duck; | ||
|
||
|
||
import fr.firstmegagame4.env.json.api.EnvJson; | ||
|
||
// Yeah, it's very awkward, I know | ||
public interface JsonObjectDuckInterface { | ||
|
||
EnvJson env_driven_assets$getEnvJson(); | ||
|
||
void env_driven_assets$setEnvJson(EnvJson envJson); | ||
} |
8 changes: 0 additions & 8 deletions
8
src/main/java/fr/firstmegagame4/env/driven/assets/client/duck/ModelLoaderDuckInterface.java
This file was deleted.
Oops, something went wrong.
7 changes: 6 additions & 1 deletion
7
...lient/injected/ModelManagerContainer.java → ...ets/client/injected/ManagerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/fr/firstmegagame4/env/driven/assets/mixin/client/JsonObjectMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fr.firstmegagame4.env.driven.assets.mixin.client; | ||
|
||
import com.google.gson.JsonObject; | ||
import fr.firstmegagame4.env.driven.assets.client.duck.JsonObjectDuckInterface; | ||
import fr.firstmegagame4.env.json.api.EnvJson; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(JsonObject.class) | ||
public class JsonObjectMixin implements JsonObjectDuckInterface { | ||
|
||
@Unique | ||
private EnvJson envJson = null; | ||
|
||
@Override | ||
public EnvJson env_driven_assets$getEnvJson() { | ||
return this.envJson; | ||
} | ||
|
||
@Override | ||
public void env_driven_assets$setEnvJson(EnvJson envJson) { | ||
this.envJson = envJson; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.