initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
156
java/src/game/model/BakedModel.java
Executable file
156
java/src/game/model/BakedModel.java
Executable file
|
@ -0,0 +1,156 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.renderer.blockmodel.BakedQuad;
|
||||
import game.renderer.blockmodel.BreakingFour;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.renderer.texture.TextureAtlasSprite;
|
||||
import game.world.Facing;
|
||||
|
||||
public class BakedModel implements IBakedModel
|
||||
{
|
||||
protected final List<BakedQuad> generalQuads;
|
||||
protected final List<List<BakedQuad>> faceQuads;
|
||||
protected final boolean ambientOcclusion;
|
||||
protected final boolean gui3d;
|
||||
protected final TextureAtlasSprite texture;
|
||||
protected final Transforms cameraTransforms;
|
||||
|
||||
public BakedModel(List<BakedQuad> generalQuadsIn, List<List<BakedQuad>> faceQuadsIn, boolean ambientOcclusionIn, boolean gui3dIn, TextureAtlasSprite textureIn, Transforms cameraTransformsIn)
|
||||
{
|
||||
this.generalQuads = generalQuadsIn;
|
||||
this.faceQuads = faceQuadsIn;
|
||||
this.ambientOcclusion = ambientOcclusionIn;
|
||||
this.gui3d = gui3dIn;
|
||||
this.texture = textureIn;
|
||||
this.cameraTransforms = cameraTransformsIn;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(Facing facing)
|
||||
{
|
||||
return this.faceQuads.get(facing.ordinal());
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return this.generalQuads;
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return this.ambientOcclusion;
|
||||
}
|
||||
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return this.gui3d;
|
||||
}
|
||||
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
public Transforms getItemCameraTransforms()
|
||||
{
|
||||
return this.cameraTransforms;
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private final List<BakedQuad> builderGeneralQuads;
|
||||
private final List<List<BakedQuad>> builderFaceQuads;
|
||||
private final boolean builderAmbientOcclusion;
|
||||
private TextureAtlasSprite builderTexture;
|
||||
private boolean builderGui3d;
|
||||
private Transforms builderCameraTransforms;
|
||||
|
||||
public Builder(ModelBlock model)
|
||||
{
|
||||
this(model.isAmbientOcclusion(), model.isGui3d(), model.getTransform());
|
||||
}
|
||||
|
||||
public Builder(IBakedModel bakedModel, TextureAtlasSprite texture)
|
||||
{
|
||||
this(bakedModel.isAmbientOcclusion(), bakedModel.isGui3d(), bakedModel.getItemCameraTransforms());
|
||||
this.builderTexture = bakedModel.getParticleTexture();
|
||||
|
||||
for (Facing enumfacing : Facing.values())
|
||||
{
|
||||
this.addFaceBreakingFours(bakedModel, texture, enumfacing);
|
||||
}
|
||||
|
||||
this.addGeneralBreakingFours(bakedModel, texture);
|
||||
}
|
||||
|
||||
private void addFaceBreakingFours(IBakedModel bakedModel, TextureAtlasSprite texture, Facing facing)
|
||||
{
|
||||
for (BakedQuad bakedquad : bakedModel.getFaceQuads(facing))
|
||||
{
|
||||
this.addFaceQuad(facing, new BreakingFour(bakedquad, texture));
|
||||
}
|
||||
}
|
||||
|
||||
private void addGeneralBreakingFours(IBakedModel p_177647_1_, TextureAtlasSprite texture)
|
||||
{
|
||||
for (BakedQuad bakedquad : p_177647_1_.getGeneralQuads())
|
||||
{
|
||||
this.addGeneralQuad(new BreakingFour(bakedquad, texture));
|
||||
}
|
||||
}
|
||||
|
||||
private Builder(boolean ambientOcclusion, boolean gui3d, Transforms cameraTransforms)
|
||||
{
|
||||
this.builderGeneralQuads = Lists.<BakedQuad>newArrayList();
|
||||
this.builderFaceQuads = new ArrayList<List<BakedQuad>>(6);
|
||||
|
||||
for (Facing enumfacing : Facing.values())
|
||||
{
|
||||
this.builderFaceQuads.add(Lists.<BakedQuad>newArrayList());
|
||||
}
|
||||
|
||||
this.builderAmbientOcclusion = ambientOcclusion;
|
||||
this.builderGui3d = gui3d;
|
||||
this.builderCameraTransforms = cameraTransforms;
|
||||
}
|
||||
|
||||
public BakedModel.Builder addFaceQuad(Facing facing, BakedQuad quad)
|
||||
{
|
||||
((List)this.builderFaceQuads.get(facing.ordinal())).add(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedModel.Builder addGeneralQuad(BakedQuad quad)
|
||||
{
|
||||
this.builderGeneralQuads.add(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedModel.Builder setTexture(TextureAtlasSprite texture)
|
||||
{
|
||||
this.builderTexture = texture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedModel makeBakedModel()
|
||||
{
|
||||
if (this.builderTexture == null)
|
||||
{
|
||||
throw new RuntimeException("Missing particle!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BakedModel(this.builderGeneralQuads, this.builderFaceQuads, this.builderAmbientOcclusion, this.builderGui3d, this.builderTexture, this.builderCameraTransforms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
java/src/game/model/BuiltInModel.java
Executable file
53
java/src/game/model/BuiltInModel.java
Executable file
|
@ -0,0 +1,53 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.renderer.blockmodel.BakedQuad;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.renderer.texture.TextureAtlasSprite;
|
||||
import game.world.Facing;
|
||||
|
||||
public class BuiltInModel implements IBakedModel
|
||||
{
|
||||
private Transforms cameraTransforms;
|
||||
|
||||
public BuiltInModel(Transforms p_i46086_1_)
|
||||
{
|
||||
this.cameraTransforms = p_i46086_1_;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(Facing facing)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Transforms getItemCameraTransforms()
|
||||
{
|
||||
return this.cameraTransforms;
|
||||
}
|
||||
}
|
25
java/src/game/model/IBakedModel.java
Executable file
25
java/src/game/model/IBakedModel.java
Executable file
|
@ -0,0 +1,25 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.renderer.blockmodel.BakedQuad;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.renderer.texture.TextureAtlasSprite;
|
||||
import game.world.Facing;
|
||||
|
||||
public interface IBakedModel
|
||||
{
|
||||
List<BakedQuad> getFaceQuads(Facing facing);
|
||||
|
||||
List<BakedQuad> getGeneralQuads();
|
||||
|
||||
boolean isAmbientOcclusion();
|
||||
|
||||
boolean isGui3d();
|
||||
|
||||
boolean isBuiltInRenderer();
|
||||
|
||||
TextureAtlasSprite getParticleTexture();
|
||||
|
||||
Transforms getItemCameraTransforms();
|
||||
}
|
325
java/src/game/model/ModelBakery.java
Executable file
325
java/src/game/model/ModelBakery.java
Executable file
|
@ -0,0 +1,325 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
import game.collect.Sets;
|
||||
import game.init.BlockRegistry;
|
||||
import game.init.FluidRegistry;
|
||||
import game.init.IRegistry;
|
||||
import game.init.ItemRegistry;
|
||||
import game.init.RegistrySimple;
|
||||
import game.item.Item;
|
||||
import game.item.ItemStack;
|
||||
import game.renderer.blockmodel.BlockPart;
|
||||
import game.renderer.blockmodel.BlockPartFace;
|
||||
import game.renderer.blockmodel.FaceBakery;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.ModelGenerator;
|
||||
import game.renderer.texture.IIconCreator;
|
||||
import game.renderer.texture.TextureAtlasSprite;
|
||||
import game.renderer.texture.TextureMap;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
|
||||
public abstract class ModelBakery
|
||||
{
|
||||
private static final Set<String> LOCATIONS_BUILTIN_TEXTURES = Sets.newHashSet(
|
||||
// "blocks/water_flow", "blocks/water_still",
|
||||
// "blocks/lava_flow", "blocks/lava_still",
|
||||
"blocks/destroy_stage_0", "blocks/destroy_stage_1",
|
||||
"blocks/destroy_stage_2", "blocks/destroy_stage_3",
|
||||
"blocks/destroy_stage_4", "blocks/destroy_stage_5",
|
||||
"blocks/destroy_stage_6", "blocks/destroy_stage_7",
|
||||
"blocks/destroy_stage_8", "blocks/destroy_stage_9",
|
||||
"items/empty_armor_slot_helmet", "items/empty_armor_slot_chestplate",
|
||||
"items/empty_armor_slot_leggings", "items/empty_armor_slot_boots");
|
||||
protected static final String MISSING = "builtin/missing" + '#' + "missing";
|
||||
public static final ModelBlock MODEL_GENERATED = new ModelBlock(null).add().d("");
|
||||
public static final ModelBlock MODEL_ENTITY = new ModelBlock(null).add().d("");
|
||||
|
||||
static {
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
String name = BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(z)).toString();
|
||||
LOCATIONS_BUILTIN_TEXTURES.add("blocks/" + name + "_flow");
|
||||
LOCATIONS_BUILTIN_TEXTURES.add("blocks/" + name + "_still");
|
||||
}
|
||||
}
|
||||
|
||||
public static IRegistry<String, IBakedModel> setupModelRegistry(TextureMap textureMap,
|
||||
Map<State, String> map)
|
||||
{
|
||||
final Map<String, TextureAtlasSprite> sprites = Maps.<String, TextureAtlasSprite>newHashMap();
|
||||
Map<String, ModelBlock> models = Maps.<String, ModelBlock>newLinkedHashMap();
|
||||
List<String> variants = Lists.<String>newArrayList();
|
||||
FaceBakery faceBakery = new FaceBakery();
|
||||
RegistrySimple<String, IBakedModel> bakedRegistry = new RegistrySimple();
|
||||
List<String> itemLocations = Lists.<String>newArrayList();
|
||||
// Map<Item, List<Integer>> variantNames = Maps.<Item, List<Integer>>newIdentityHashMap();
|
||||
// variants.clear();
|
||||
// Map<IBlockState, String> map = blockModelShapes.getMap();
|
||||
models.put(MISSING, new ModelBlock(null).add().all());
|
||||
variants.add(MISSING);
|
||||
for(Entry<State, String> entry : map.entrySet()) {
|
||||
ModelBlock model = entry.getKey().getBlock().getModel(BlockRegistry.REGISTRY.getNameForObject(entry.getKey().getBlock())
|
||||
.toString(), entry.getKey());
|
||||
// ResourceLocation blk = new ResourceLocation(entry.getValue().getName());
|
||||
models.put(entry.getValue(), model);
|
||||
variants.add(entry.getValue());
|
||||
}
|
||||
// ResourceLocation loc = new ResourceLocation("item_frame");
|
||||
// String res = "item_frame" + '#' + "normal";
|
||||
// ModelBlock model = new ModelBlock("birch_planks")
|
||||
// .add(3, 3, 15.5f, 13, 13, 16)
|
||||
// .n("itemframe_background").uv(3, 3, 13, 13).noCull()
|
||||
// .s("itemframe_background").uv(3, 3, 13, 13).noCull()
|
||||
// .add(2, 2, 15, 14, 3, 16)
|
||||
// .d().uv(2, 0, 14, 1).noCull()
|
||||
// .u().uv(2, 15, 14, 16).noCull()
|
||||
// .n().uv(2, 13, 14, 14).noCull()
|
||||
// .s().uv(2, 13, 14, 14).noCull()
|
||||
// .w().uv(15, 13, 16, 14).noCull()
|
||||
// .e().uv(0, 13, 1, 14).noCull()
|
||||
// .add(2, 13, 15, 14, 14, 16)
|
||||
// .d().uv(2, 0, 14, 1).noCull()
|
||||
// .u().uv(2, 15, 14, 16).noCull()
|
||||
// .n().uv(2, 2, 14, 3).noCull()
|
||||
// .s().uv(2, 2, 14, 3).noCull()
|
||||
// .w().uv(15, 2, 16, 3).noCull()
|
||||
// .e().uv(0, 2, 1, 3).noCull()
|
||||
// .add(2, 3, 15, 3, 13, 16)
|
||||
// .n().uv(13, 3, 14, 13).noCull()
|
||||
// .s().uv(2, 3, 3, 13).noCull()
|
||||
// .w().uv(15, 3, 16, 13).noCull()
|
||||
// .e().uv(0, 3, 1, 13).noCull()
|
||||
// .add(13, 3, 15, 14, 13, 16)
|
||||
// .n().uv(2, 3, 3, 13).noCull()
|
||||
// .s().uv(13, 3, 14, 13).noCull()
|
||||
// .w().uv(15, 3, 16, 13).noCull()
|
||||
// .e().uv(0, 3, 1, 13).noCull();
|
||||
// models.put(res, model);
|
||||
// variants.add(res);
|
||||
// res = "item_frame" + '#' + "map";
|
||||
// model = new ModelBlock("birch_planks")
|
||||
// .add(1, 1, 15.001f, 15, 15, 16)
|
||||
// .n("itemframe_background").uv(1, 1, 15, 15).noCull()
|
||||
// .s("itemframe_background").uv(1, 1, 15, 15).noCull()
|
||||
// .add(0, 0, 15.001f, 16, 1, 16)
|
||||
// .d().uv(0, 0, 16, 1).noCull()
|
||||
// .u().uv(0, 15, 16, 16).noCull()
|
||||
// .n().uv(0, 15, 16, 16).noCull()
|
||||
// .s().uv(0, 15, 16, 16).noCull()
|
||||
// .w().uv(15, 15, 16, 16).noCull()
|
||||
// .e().uv(0, 15, 1, 16).noCull()
|
||||
// .add(0, 15, 15.001f, 16, 16, 16)
|
||||
// .d().uv(0, 0, 16, 1).noCull()
|
||||
// .u().uv(0, 15, 16, 16).noCull()
|
||||
// .n().uv(0, 0, 16, 1).noCull()
|
||||
// .s().uv(0, 0, 16, 1).noCull()
|
||||
// .w().uv(15, 0, 16, 1).noCull()
|
||||
// .e().uv(0, 0, 1, 1).noCull()
|
||||
// .add(0, 1, 15.001f, 1, 15, 16)
|
||||
// .n().uv(15, 1, 16, 15).noCull()
|
||||
// .s().uv(0, 1, 1, 15).noCull()
|
||||
// .w().uv(15, 1, 16, 15).noCull()
|
||||
// .e().uv(0, 1, 1, 15).noCull()
|
||||
// .add(15, 1, 15.001f, 16, 15, 16)
|
||||
// .n().uv(0, 1, 1, 15).noCull()
|
||||
// .s().uv(15, 1, 16, 15).noCull()
|
||||
// .w().uv(15, 1, 16, 15).noCull()
|
||||
// .e().uv(0, 1, 1, 15).noCull();
|
||||
// models.put(res, model);
|
||||
// variants.add(res);
|
||||
|
||||
// RenderRegistry.registerVariants(variantNames);
|
||||
List<ItemStack> stacks = Lists.newArrayList();
|
||||
for (Item item : ItemRegistry.REGISTRY)
|
||||
{
|
||||
// List<Integer> list = variantNames.get(item);
|
||||
// if(list == null)
|
||||
// list = Collections.<Integer>singletonList(0);
|
||||
// for(Integer s : list)
|
||||
// {
|
||||
item.getRenderItems(item, stacks);
|
||||
for(ItemStack stack : stacks) {
|
||||
String resourcelocation = "item/" + ItemRegistry.REGISTRY.getNameForObject(item).toString() + "#" + stack.getMetadata() + '#' + "inventory";
|
||||
models.put(resourcelocation, item.getModel(ItemRegistry.REGISTRY.getNameForObject(item).toString(), stack.getMetadata()));
|
||||
itemLocations.add(resourcelocation);
|
||||
}
|
||||
stacks.clear();
|
||||
}
|
||||
|
||||
final Set<String> set = Sets.<String>newHashSet();
|
||||
List<String> list = Lists.newArrayList(variants);
|
||||
Collections.sort(list, new Comparator<String>()
|
||||
{
|
||||
public int compare(String p_compare_1_, String p_compare_2_)
|
||||
{
|
||||
return p_compare_1_.compareTo(p_compare_2_);
|
||||
}
|
||||
});
|
||||
|
||||
for (String modelresourcelocation : list)
|
||||
{
|
||||
ModelBlock modelblock = models.get(modelresourcelocation);
|
||||
|
||||
if (modelblock == null)
|
||||
{
|
||||
throw new RuntimeException("Fehlendes Modell für: " + modelresourcelocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (BlockPart blockpart : modelblock.getElements())
|
||||
{
|
||||
for (BlockPartFace blockpartface : blockpart.mapFaces.values())
|
||||
{
|
||||
set.add(blockpartface.texture);
|
||||
}
|
||||
}
|
||||
|
||||
set.add(modelblock.getPrimary());
|
||||
// return set;
|
||||
// set.addAll(getTextureLocations(modelblock));
|
||||
}
|
||||
}
|
||||
|
||||
set.addAll(LOCATIONS_BUILTIN_TEXTURES);
|
||||
// final Set<ResourceLocation> set = getVariantsTextureLocations();
|
||||
for (String resourcelocation : itemLocations) // .values())
|
||||
{
|
||||
ModelBlock modelblock = (ModelBlock)models.get(resourcelocation);
|
||||
|
||||
if (modelblock != null)
|
||||
{
|
||||
set.add(modelblock.getPrimary());
|
||||
|
||||
if (modelblock.getParent() == MODEL_GENERATED)
|
||||
{
|
||||
for (int n = 0; n < modelblock.getNumTextures(); n++)
|
||||
{
|
||||
set.add(modelblock.getTexture(n));
|
||||
}
|
||||
}
|
||||
else if (modelblock.getParent() != MODEL_ENTITY)
|
||||
{
|
||||
for (BlockPart blockpart : modelblock.getElements())
|
||||
{
|
||||
for (BlockPartFace blockpartface : blockpart.mapFaces.values())
|
||||
{
|
||||
set.add(blockpartface.texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set.addAll(getItemsTextureLocations());
|
||||
set.remove(TextureMap.LOCATION_MISSING_TEXTURE);
|
||||
IIconCreator iiconcreator = new IIconCreator()
|
||||
{
|
||||
public void registerSprites(TextureMap iconRegistry)
|
||||
{
|
||||
for (String resourcelocation : set)
|
||||
{
|
||||
TextureAtlasSprite textureatlassprite = iconRegistry.registerSprite(resourcelocation);
|
||||
sprites.put(resourcelocation, textureatlassprite);
|
||||
}
|
||||
}
|
||||
};
|
||||
textureMap.loadSprites(iiconcreator);
|
||||
sprites.put(TextureMap.LOCATION_MISSING_TEXTURE, textureMap.getMissingSprite());
|
||||
|
||||
for (String resourcelocation : itemLocations) // .values())
|
||||
{
|
||||
ModelBlock modelblock = models.get(resourcelocation);
|
||||
|
||||
if (modelblock != null && modelblock.getParent() == MODEL_GENERATED)
|
||||
{
|
||||
ModelBlock modelblock1 = ModelGenerator.makeItemModel(textureMap, modelblock);
|
||||
models.put(resourcelocation, modelblock1);
|
||||
}
|
||||
else if (modelblock != null && modelblock.getParent() == MODEL_ENTITY)
|
||||
{
|
||||
models.put(resourcelocation, modelblock);
|
||||
}
|
||||
}
|
||||
|
||||
for (TextureAtlasSprite textureatlassprite : sprites.values())
|
||||
{
|
||||
if (!textureatlassprite.isAnimated())
|
||||
{
|
||||
textureatlassprite.clearFramesTextureData();
|
||||
}
|
||||
}
|
||||
|
||||
for (String modelresourcelocation : variants)
|
||||
{
|
||||
ModelBlock modelblock = models.get(modelresourcelocation);
|
||||
|
||||
if (modelblock != null)
|
||||
{
|
||||
bakedRegistry.putObject(modelresourcelocation, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(),
|
||||
modelblock, modelblock.getRotation(), modelblock.isUvLocked()));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException("Fehlendes Modell für: " + modelresourcelocation);
|
||||
}
|
||||
}
|
||||
|
||||
// for (Entry<String, ResourceLocation> entry : itemLocations.entrySet())
|
||||
for (String entry : itemLocations)
|
||||
{
|
||||
// ResourceLocation resourcelocation = (ResourceLocation)entry.getValue();
|
||||
// ResourceLocation inventory = new ResourceLocation((String)entry.getKey(), "inventory");
|
||||
ModelBlock modelblock1 = (ModelBlock)models.get(entry) ; // resourcelocation);
|
||||
|
||||
if (modelblock1 != null)
|
||||
{
|
||||
if (modelblock1.getParent() == MODEL_ENTITY)
|
||||
{
|
||||
bakedRegistry.putObject(entry /* inventory */, new BuiltInModel(modelblock1.getTransform()));
|
||||
}
|
||||
else
|
||||
{
|
||||
bakedRegistry.putObject(entry /* inventory */, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(),
|
||||
modelblock1, ModelRotation.X0_Y0, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException("Fehlendes Modell für: " + entry); // resourcelocation);
|
||||
}
|
||||
}
|
||||
|
||||
return bakedRegistry;
|
||||
}
|
||||
|
||||
private static IBakedModel bakeModel(Map<String, TextureAtlasSprite> sprites, FaceBakery faceBakery,
|
||||
TextureAtlasSprite fallback, ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked)
|
||||
{
|
||||
TextureAtlasSprite particle = sprites.get(modelBlockIn.getPrimary());
|
||||
BakedModel.Builder builder = new BakedModel.Builder(modelBlockIn).setTexture(particle == null ? fallback : particle);
|
||||
for (BlockPart blockpart : modelBlockIn.getElements())
|
||||
{
|
||||
for (Facing enumfacing : blockpart.mapFaces.keySet())
|
||||
{
|
||||
BlockPartFace face = blockpart.mapFaces.get(enumfacing);
|
||||
TextureAtlasSprite sprite = sprites.get(face.texture);
|
||||
sprite = sprite == null ? fallback : sprite;
|
||||
|
||||
if (face.cull == null)
|
||||
builder.addGeneralQuad(faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade));
|
||||
else
|
||||
builder.addFaceQuad(modelRotationIn.rotateFace(face.cull), faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade));
|
||||
}
|
||||
}
|
||||
return builder.makeBakedModel();
|
||||
}
|
||||
}
|
168
java/src/game/model/ModelManager.java
Executable file
168
java/src/game/model/ModelManager.java
Executable file
|
@ -0,0 +1,168 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockLiquid;
|
||||
import game.collect.Maps;
|
||||
import game.init.BlockRegistry;
|
||||
import game.init.Blocks;
|
||||
import game.init.FluidRegistry;
|
||||
import game.init.IRegistry;
|
||||
import game.properties.IProperty;
|
||||
import game.renderer.blockmodel.MultiStateMap;
|
||||
import game.renderer.blockmodel.SingleStateMap;
|
||||
import game.renderer.blockmodel.StateMap;
|
||||
import game.renderer.texture.TextureAtlasSprite;
|
||||
import game.renderer.texture.TextureMap;
|
||||
import game.world.State;
|
||||
|
||||
public class ModelManager
|
||||
{
|
||||
private IRegistry<String, IBakedModel> modelRegistry;
|
||||
private final TextureMap texMap;
|
||||
private final Map<State, IBakedModel> bakedModelStore = Maps.<State, IBakedModel>newIdentityHashMap();
|
||||
private final Map<Block, String> liquidMap = Maps.<Block, String>newIdentityHashMap();
|
||||
private final Map<Block, StateMap> mappers = Maps.<Block, StateMap>newIdentityHashMap();
|
||||
private final Set<Block> builtin = Collections.newSetFromMap(Maps.<Block, Boolean>newIdentityHashMap());
|
||||
private IBakedModel defaultModel;
|
||||
|
||||
public ModelManager(TextureMap textures)
|
||||
{
|
||||
this.texMap = textures;
|
||||
for(Block block : BlockRegistry.REGISTRY) {
|
||||
if(block.getRenderType() != 3) {
|
||||
this.builtin.add(block);
|
||||
// Log.info("Builtin: " + BlockRegistry.REGISTRY.getNameForObject(block));
|
||||
}
|
||||
else {
|
||||
IProperty<?>[] ignored = block.getIgnoredProperties();
|
||||
if(ignored != null)
|
||||
this.mappers.put(block, new MultiStateMap.Builder().ignore(ignored).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onReload()
|
||||
{
|
||||
this.modelRegistry = ModelBakery.setupModelRegistry(this.texMap, this.getMap());
|
||||
this.defaultModel = this.modelRegistry.getObject(ModelBakery.MISSING);
|
||||
this.reloadModels();
|
||||
}
|
||||
|
||||
public IBakedModel getModel(String modelLocation)
|
||||
{
|
||||
if (modelLocation == null)
|
||||
{
|
||||
return this.defaultModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBakedModel ibakedmodel = this.modelRegistry.getObject(modelLocation);
|
||||
return ibakedmodel == null ? this.defaultModel : ibakedmodel;
|
||||
}
|
||||
}
|
||||
|
||||
public IBakedModel getMissingModel()
|
||||
{
|
||||
return this.defaultModel;
|
||||
}
|
||||
|
||||
public TextureMap getTextureMap()
|
||||
{
|
||||
return this.texMap;
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getTexture(State state)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
IBakedModel ibakedmodel = this.getModelForState(state);
|
||||
|
||||
if (ibakedmodel == null || ibakedmodel == this.defaultModel)
|
||||
{
|
||||
if (block == Blocks.wall_sign || block == Blocks.sign || block == Blocks.chest || block == Blocks.trapped_chest || block == Blocks.banner || block == Blocks.wall_banner)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/oak_planks");
|
||||
}
|
||||
|
||||
if (block == Blocks.floor_portal)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/obsidian");
|
||||
}
|
||||
|
||||
if (block == Blocks.flowing_lava || block == Blocks.lava)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/lava_still");
|
||||
}
|
||||
|
||||
if (block == Blocks.flowing_water || block == Blocks.water)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/water_still");
|
||||
}
|
||||
|
||||
if (block == Blocks.skull)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/soul_sand");
|
||||
}
|
||||
|
||||
// if (block == Blocks.barrier)
|
||||
// {
|
||||
// return this.modelManager.getTextureMap().getAtlasSprite("items/barrier");
|
||||
// }
|
||||
|
||||
if (block.getMaterial().isLiquid())
|
||||
{
|
||||
String texture = this.liquidMap.get(block);
|
||||
if(texture == null)
|
||||
this.liquidMap.put(block, texture = "blocks/" + BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(FluidRegistry.getFluidMeta((BlockLiquid)block))) + "_still");
|
||||
return this.texMap.getAtlasSprite(texture);
|
||||
}
|
||||
}
|
||||
|
||||
if (ibakedmodel == null)
|
||||
{
|
||||
ibakedmodel = this.defaultModel;
|
||||
}
|
||||
|
||||
return ibakedmodel.getParticleTexture();
|
||||
}
|
||||
|
||||
public IBakedModel getModelForState(State state)
|
||||
{
|
||||
IBakedModel ibakedmodel = (IBakedModel)this.bakedModelStore.get(state);
|
||||
|
||||
if (ibakedmodel == null)
|
||||
{
|
||||
ibakedmodel = this.defaultModel;
|
||||
}
|
||||
|
||||
return ibakedmodel;
|
||||
}
|
||||
|
||||
public void reloadModels()
|
||||
{
|
||||
this.bakedModelStore.clear();
|
||||
|
||||
for (Entry<State, String> entry : this.getMap().entrySet())
|
||||
{
|
||||
this.bakedModelStore.put(entry.getKey(), this.getModel(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<State, String> getMap() {
|
||||
Map<State, String> map = Maps.<State, String>newIdentityHashMap();
|
||||
for(Block block : BlockRegistry.REGISTRY) {
|
||||
if(!this.builtin.contains(block)) {
|
||||
StateMap mapper = this.mappers.get(block);
|
||||
if(mapper == null)
|
||||
mapper = new SingleStateMap();
|
||||
map.putAll( // (Objects.firstNonNull(, ))
|
||||
mapper.putStateModelLocations(block));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
154
java/src/game/model/ModelRotation.java
Executable file
154
java/src/game/model/ModelRotation.java
Executable file
|
@ -0,0 +1,154 @@
|
|||
package game.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.collect.Maps;
|
||||
import game.renderer.Matrix4f;
|
||||
import game.renderer.Vector3f;
|
||||
import game.world.Facing;
|
||||
|
||||
public enum ModelRotation
|
||||
{
|
||||
X0_Y0(0, 0),
|
||||
X0_Y90(0, 90),
|
||||
X0_Y180(0, 180),
|
||||
X0_Y270(0, 270),
|
||||
X90_Y0(90, 0),
|
||||
X90_Y90(90, 90),
|
||||
X90_Y180(90, 180),
|
||||
X90_Y270(90, 270),
|
||||
X180_Y0(180, 0),
|
||||
X180_Y90(180, 90),
|
||||
X180_Y180(180, 180),
|
||||
X180_Y270(180, 270),
|
||||
X270_Y0(270, 0),
|
||||
X270_Y90(270, 90),
|
||||
X270_Y180(270, 180),
|
||||
X270_Y270(270, 270);
|
||||
|
||||
private static final Map<Integer, ModelRotation> mapRotations = Maps.<Integer, ModelRotation>newHashMap();
|
||||
private final int combinedXY;
|
||||
private final Matrix4f matrix4d;
|
||||
private final int quartersX;
|
||||
private final int quartersY;
|
||||
|
||||
private static int combineXY(int p_177521_0_, int p_177521_1_)
|
||||
{
|
||||
return p_177521_0_ * 360 + p_177521_1_;
|
||||
}
|
||||
|
||||
private ModelRotation(int p_i46087_3_, int p_i46087_4_)
|
||||
{
|
||||
this.combinedXY = combineXY(p_i46087_3_, p_i46087_4_);
|
||||
this.matrix4d = new Matrix4f();
|
||||
Matrix4f matrix4f = new Matrix4f();
|
||||
matrix4f.setIdentity();
|
||||
Matrix4f.rotate((float)(-p_i46087_3_) * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), matrix4f, matrix4f);
|
||||
this.quartersX = ExtMath.absi(p_i46087_3_ / 90);
|
||||
Matrix4f matrix4f1 = new Matrix4f();
|
||||
matrix4f1.setIdentity();
|
||||
Matrix4f.rotate((float)(-p_i46087_4_) * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), matrix4f1, matrix4f1);
|
||||
this.quartersY = ExtMath.absi(p_i46087_4_ / 90);
|
||||
Matrix4f.mul(matrix4f1, matrix4f, this.matrix4d);
|
||||
}
|
||||
|
||||
public Matrix4f getMatrix4d()
|
||||
{
|
||||
return this.matrix4d;
|
||||
}
|
||||
|
||||
public Facing rotateFace(Facing p_177523_1_)
|
||||
{
|
||||
Facing enumfacing = p_177523_1_;
|
||||
|
||||
for (int i = 0; i < this.quartersX; ++i)
|
||||
{
|
||||
enumfacing = enumfacing.rotateAround(Facing.Axis.X);
|
||||
}
|
||||
|
||||
if (enumfacing.getAxis() != Facing.Axis.Y)
|
||||
{
|
||||
for (int j = 0; j < this.quartersY; ++j)
|
||||
{
|
||||
enumfacing = enumfacing.rotateAround(Facing.Axis.Y);
|
||||
}
|
||||
}
|
||||
|
||||
return enumfacing;
|
||||
}
|
||||
|
||||
public int rotateVertex(Facing facing, int vertexIndex)
|
||||
{
|
||||
int i = vertexIndex;
|
||||
|
||||
if (facing.getAxis() == Facing.Axis.X)
|
||||
{
|
||||
i = (vertexIndex + this.quartersX) % 4;
|
||||
}
|
||||
|
||||
Facing enumfacing = facing;
|
||||
|
||||
for (int j = 0; j < this.quartersX; ++j)
|
||||
{
|
||||
enumfacing = enumfacing.rotateAround(Facing.Axis.X);
|
||||
}
|
||||
|
||||
if (enumfacing.getAxis() == Facing.Axis.Y)
|
||||
{
|
||||
i = (i + this.quartersY) % 4;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static ModelRotation getModelRotation(int p_177524_0_, int p_177524_1_)
|
||||
{
|
||||
return (ModelRotation)mapRotations.get(Integer.valueOf(combineXY((p_177524_0_ % 360 + 360) % 360, (p_177524_1_ % 360 + 360) % 360)));
|
||||
}
|
||||
|
||||
public static ModelRotation getNorthRot(Facing face)
|
||||
{
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
default:
|
||||
return X0_Y0;
|
||||
case SOUTH:
|
||||
return X0_Y180;
|
||||
case WEST:
|
||||
return X0_Y270;
|
||||
case EAST:
|
||||
return X0_Y90;
|
||||
case DOWN:
|
||||
return X270_Y0;
|
||||
case UP:
|
||||
return X90_Y0;
|
||||
}
|
||||
}
|
||||
|
||||
public static ModelRotation getEastRot(Facing face, boolean flip)
|
||||
{
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
default:
|
||||
return flip ? X180_Y270 : X0_Y270;
|
||||
case SOUTH:
|
||||
return flip ? X180_Y90 : X0_Y90;
|
||||
case WEST:
|
||||
return flip ? X180_Y180 : X0_Y180;
|
||||
case EAST:
|
||||
return flip ? X180_Y0 : X0_Y0;
|
||||
case DOWN:
|
||||
return X270_Y0;
|
||||
case UP:
|
||||
return X90_Y0;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
for (ModelRotation modelrotation : values())
|
||||
{
|
||||
mapRotations.put(Integer.valueOf(modelrotation.combinedXY), modelrotation);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue