mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Clean Up Wood Model Loader
This commit is contained in:
1 parent
81dd20b41c
commit
6a12e19798
27 files changed
+641
-448
No files matched your search
@@ -23,5 +23,8 @@ public interface IAlleleButterflyCocoon extends IAlleleProperty<IAlleleButterfly
|
||||
String getCocoonName();
|
||||
|
||||
Map<ItemStack, Float> getCocoonLoot();
|
||||
|
||||
void clearLoot();
|
||||
|
||||
void addLoot(ItemStack loot, float chance);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class WoodHelper {
|
||||
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
if (!WoodModelLoader.INSTANCE.isRegistered) {
|
||||
if (!WoodModelLoader.INSTANCE.isEnabled) {
|
||||
return new ModelResourceLocation(getDefaultModelLocation(stack), "inventory");
|
||||
}
|
||||
int meta = stack.getMetadata();
|
||||
|
||||
@@ -22,7 +22,9 @@ import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -51,13 +53,14 @@ public class BlockArbDoor extends BlockDoor implements IWoodTyped, IItemModelReg
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, null).addPropertyToRemove(POWERED));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this,
|
||||
new WoodTypeStateMapper(this, null).addPropertyToRemove(POWERED));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,9 +9,11 @@ import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.proxy.ProxyApicultureClient;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFence;
|
||||
@@ -99,7 +101,7 @@ public abstract class BlockForestryFence<T extends Enum<T> & IWoodType> extends
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,6 +177,6 @@ public abstract class BlockForestryFence<T extends Enum<T> & IWoodType> extends
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.WoodHelper.WoodMeshDefinition;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockPlanks.EnumType;
|
||||
@@ -95,7 +96,7 @@ public class BlockForestryFenceGate<T extends Enum<T> & IWoodType> extends Block
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, null).addPropertyToRemove(POWERED));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, null).addPropertyToRemove(POWERED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,6 +115,6 @@ public class BlockForestryFenceGate<T extends Enum<T> & IWoodType> extends Block
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodMeshDefinition(this));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.BlockLog;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
@@ -166,12 +167,12 @@ public abstract class BlockForestryLog<T extends Enum<T> & IWoodType> extends Bl
|
||||
@Override
|
||||
public final void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
@@ -113,13 +114,13 @@ public abstract class BlockForestryPlanks<T extends Enum<T> & IWoodType> extends
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, getVariant()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.SoundType;
|
||||
@@ -126,7 +127,7 @@ public abstract class BlockForestrySlab<T extends Enum<T> & IWoodType> extends B
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,6 +186,6 @@ public abstract class BlockForestrySlab<T extends Enum<T> & IWoodType> extends B
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
String blockPath = isDouble() ? "double_slab" : getBlockKind().toString();
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, blockPath, getVariant()));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, blockPath, getVariant()));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.WoodHelper;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -40,13 +41,13 @@ public class BlockForestryStairs<T extends Enum<T> & IWoodType> extends BlockSta
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ModelBakery.registerItemVariants(item, WoodHelper.getDefaultResourceLocations(this));
|
||||
manager.registerItemModel(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
ProxyArboricultureClient.registerWoodMeshDefinition(item, new WoodHelper.WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new WoodTypeStateMapper(this, null));
|
||||
ProxyArboricultureClient.registerWoodStateMapper(this, new WoodTypeStateMapper(this, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public class WoodTypeStateMapper extends StateMapperBase implements IWoodStateMa
|
||||
int meta = block.getMetaFromState(state);
|
||||
IWoodType woodType = woodTyped.getWoodType(meta);
|
||||
if (woodType instanceof EnumForestryWoodType) {
|
||||
if (WoodModelLoader.INSTANCE.isRegistered) {
|
||||
if (WoodModelLoader.INSTANCE.isEnabled) {
|
||||
return getForestryModelResourceLocation(woodType, properties);
|
||||
} else {
|
||||
return getDefaultModelResourceLocation(state);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package forestry.arboriculture.models;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.MultipartBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Multipart;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Selector;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IRetexturableModel;
|
||||
import net.minecraftforge.client.model.ModelProcessingHelper;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
public class MultipartModel implements IRetexturableModel {
|
||||
|
||||
private final ResourceLocation location;
|
||||
private final Multipart multipart;
|
||||
private final ImmutableMap<Selector, IModel> partModels;
|
||||
|
||||
public MultipartModel(ResourceLocation location, Multipart multipart) throws Exception {
|
||||
this.location = location;
|
||||
this.multipart = multipart;
|
||||
ImmutableMap.Builder<Selector, IModel> builder = ImmutableMap.builder();
|
||||
for (Selector selector : multipart.getSelectors()) {
|
||||
builder.put(selector, new SimpleModel(location, selector.getVariantList()));
|
||||
}
|
||||
partModels = builder.build();
|
||||
}
|
||||
|
||||
private MultipartModel(ResourceLocation location, Multipart multipart, ImmutableMap<Selector, IModel> partModels)
|
||||
throws Exception {
|
||||
this.location = location;
|
||||
this.multipart = multipart;
|
||||
this.partModels = partModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelState state, VertexFormat format,
|
||||
Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
MultipartBakedModel.Builder builder = new MultipartBakedModel.Builder();
|
||||
|
||||
for (Selector selector : multipart.getSelectors()) {
|
||||
IModel model = partModels.get(selector);
|
||||
IBakedModel bakedModel = model.bake(model.getDefaultState(), format, bakedTextureGetter);
|
||||
builder.putModel(selector.getPredicate(multipart.getStateContainer()), bakedModel);
|
||||
}
|
||||
|
||||
return builder.makeMultipartModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures) {
|
||||
try {
|
||||
ImmutableMap.Builder<Selector, IModel> builder = ImmutableMap.builder();
|
||||
for (Selector selector : multipart.getSelectors()) {
|
||||
IModel model = new SimpleModel(location, selector.getVariantList());
|
||||
model = ModelProcessingHelper.retexture(model, textures);
|
||||
builder.put(selector, model);
|
||||
}
|
||||
return new MultipartModel(location, multipart, builder.build());
|
||||
} catch (Exception e) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Multipart getMultipart() {
|
||||
return multipart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState() {
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package forestry.arboriculture.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.renderer.block.model.VariantList;
|
||||
import net.minecraft.client.renderer.block.model.WeightedBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IRetexturableModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelProcessingHelper;
|
||||
import net.minecraftforge.client.model.MultiModelState;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
public class SimpleModel implements IRetexturableModel {
|
||||
|
||||
private static final ModelResourceLocation MISSING = new ModelResourceLocation("builtin/missing", "missing");
|
||||
|
||||
private final List<Variant> variants;
|
||||
private final List<ResourceLocation> locations = new ArrayList<>();
|
||||
private final Set<ResourceLocation> textures = Sets.newHashSet();
|
||||
private final List<IModel> models = new ArrayList<>();
|
||||
private final IModelState defaultState;
|
||||
|
||||
public SimpleModel(List<ResourceLocation> locations, List<IModel> models, List<Variant> variants,
|
||||
IModelState defaultState) {
|
||||
this.locations.addAll(locations);
|
||||
this.models.addAll(models);
|
||||
this.variants = variants;
|
||||
this.defaultState = defaultState;
|
||||
for (IModel model : models) {
|
||||
textures.addAll(model.getTextures());
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleModel(ResourceLocation parent, VariantList variants) throws Exception {
|
||||
this.variants = variants.getVariantList();
|
||||
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
|
||||
for (Variant variant : this.variants) {
|
||||
ResourceLocation loc = variant.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
IModel model;
|
||||
if (loc.equals(MISSING)) {
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
} else {
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
}
|
||||
|
||||
model = variant.process(model);
|
||||
for (ResourceLocation location : model.getDependencies()) {
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
textures.addAll(model.getTextures());
|
||||
|
||||
models.add(model);
|
||||
builder.add(Pair.of(model, variant.getState()));
|
||||
}
|
||||
|
||||
if (models.size() == 0) {
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.of(missing, TRSRTransformation.identity()));
|
||||
}
|
||||
|
||||
defaultState = new MultiModelState(builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return ImmutableList.copyOf(locations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
return ImmutableSet.copyOf(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelState state, VertexFormat format,
|
||||
Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
if (variants.size() == 1) {
|
||||
IModel model = models.get(0);
|
||||
return model.bake(MultiModelState.getPartState(state, model, 0), format, bakedTextureGetter);
|
||||
} else {
|
||||
WeightedBakedModel.Builder builder = new WeightedBakedModel.Builder();
|
||||
for (int i = 0; i < variants.size(); i++) {
|
||||
IModel model = models.get(i);
|
||||
builder.add(model.bake(MultiModelState.getPartState(state, model, i), format, bakedTextureGetter),
|
||||
variants.get(i).getWeight());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures) {
|
||||
List<IModel> models = new ArrayList<>();
|
||||
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
|
||||
for (Variant variant : this.variants) {
|
||||
ResourceLocation loc = variant.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
IModel model;
|
||||
if (loc.equals(MISSING)) {
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
} else {
|
||||
try {
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
model = variant.process(model);
|
||||
for (ResourceLocation location : model.getDependencies()) {
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
model = ModelProcessingHelper.retexture(model, textures);
|
||||
|
||||
models.add(model);
|
||||
builder.add(Pair.of(model, variant.getState()));
|
||||
}
|
||||
|
||||
if (models.isEmpty()) {
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.of(missing, TRSRTransformation.identity()));
|
||||
}
|
||||
return new SimpleModel(locations, models, variants, new MultiModelState(builder.build()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,56 +4,30 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.ModelUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.renderer.block.model.VariantList;
|
||||
import net.minecraft.client.renderer.block.model.WeightedBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IRetexturableModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelProcessingHelper;
|
||||
import net.minecraftforge.client.model.MultiModel;
|
||||
import net.minecraftforge.client.model.MultiModelState;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public enum WoodModelLoader implements ICustomModelLoader {
|
||||
INSTANCE;
|
||||
|
||||
public static final Map<ResourceLocation, Exception> loadingExceptions = Maps.newHashMap();
|
||||
private final Map<ResourceLocation, ModelBlockDefinition> blockDefinitions = Maps.newHashMap();
|
||||
public static final List<String> validFiles = new ArrayList<>();
|
||||
public boolean isRegistered = false;
|
||||
public boolean isEnabled = false;
|
||||
|
||||
static {
|
||||
validFiles.add("door");
|
||||
@@ -73,7 +47,9 @@ public enum WoodModelLoader implements ICustomModelLoader {
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation) {
|
||||
if (!(modelLocation instanceof ModelResourceLocation) || !modelLocation.getResourceDomain().equals(Constants.MOD_ID) || !modelLocation.getResourcePath().contains("arboriculture")) {
|
||||
if (!isEnabled || !(modelLocation instanceof ModelResourceLocation)
|
||||
|| !modelLocation.getResourceDomain().equals(Constants.MOD_ID)
|
||||
|| !modelLocation.getResourcePath().contains("arboriculture")) {
|
||||
return false;
|
||||
}
|
||||
String path = modelLocation.getResourcePath();
|
||||
@@ -88,199 +64,16 @@ public enum WoodModelLoader implements ICustomModelLoader {
|
||||
@Override
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
|
||||
ModelResourceLocation variant = (ModelResourceLocation) modelLocation;
|
||||
ModelBlockDefinition definition = getModelBlockDefinition(variant);
|
||||
ModelBlockDefinition definition = ModelUtil.getModelBlockDefinition(variant);
|
||||
try {
|
||||
VariantList variants = definition.getVariant(variant.getVariant());
|
||||
return new WeightedRandomModel(variant, variants);
|
||||
return new SimpleModel(variant, variants);
|
||||
} catch (MissingVariantException e) {
|
||||
if (definition.hasMultipartData()) {
|
||||
Log.error("The forestry model loader can't load the model with the location: %s, because it dons't support multipart models.", modelLocation.toString());
|
||||
return new MultipartModel(new ResourceLocation(variant.getResourceDomain(), variant.getResourcePath()),
|
||||
definition.getMultipartData());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/* MODEL LOADER PRIVATE METHODS */
|
||||
private ModelBlockDefinition getModelBlockDefinition(ResourceLocation location) {
|
||||
try {
|
||||
ResourceLocation resourcelocation = this.getBlockstateLocation(location);
|
||||
return this.blockDefinitions.computeIfAbsent(resourcelocation, k -> this.loadMultipartMBD(location, resourcelocation));
|
||||
} catch (Exception exception) {
|
||||
loadingExceptions.put(location, new Exception("Could not load model definition for variant " + location, exception));
|
||||
}
|
||||
return new ModelBlockDefinition(new ArrayList<>());
|
||||
}
|
||||
|
||||
private ResourceLocation getBlockstateLocation(ResourceLocation location) {
|
||||
return new ResourceLocation(location.getResourceDomain(), "blockstates/" + location.getResourcePath() + ".json");
|
||||
}
|
||||
|
||||
private ModelBlockDefinition loadMultipartMBD(ResourceLocation location, ResourceLocation fileIn) {
|
||||
List<ModelBlockDefinition> list = Lists.newArrayList();
|
||||
|
||||
try {
|
||||
for (IResource iresource : Minecraft.getMinecraft().getResourceManager().getAllResources(fileIn)) {
|
||||
list.add(this.loadModelBlockDefinition(location, iresource));
|
||||
}
|
||||
} catch (IOException ioexception) {
|
||||
throw new RuntimeException("Encountered an exception when loading model definition of model " + fileIn, ioexception);
|
||||
}
|
||||
|
||||
return new ModelBlockDefinition(list);
|
||||
}
|
||||
|
||||
private ModelBlockDefinition loadModelBlockDefinition(ResourceLocation location, IResource iresource) {
|
||||
InputStream inputstream = null;
|
||||
ModelBlockDefinition definition;
|
||||
|
||||
try {
|
||||
inputstream = iresource.getInputStream();
|
||||
definition = ModelBlockDefinition.parseFromReader(new InputStreamReader(inputstream, Charsets.UTF_8));
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException("Encountered an exception when loading model definition of \'" + location + "\' from: \'" + iresource.getResourceLocation() + "\' in resourcepack: \'" + iresource.getResourcePackName() + "\'", exception);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputstream);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
private class WeightedRandomModel implements IRetexturableModel {
|
||||
private final List<Variant> variants;
|
||||
private final List<ResourceLocation> locations = new ArrayList<>();
|
||||
private final Set<ResourceLocation> textures = Sets.newHashSet();
|
||||
private final List<IModel> models = new ArrayList<>();
|
||||
private final IModelState defaultState;
|
||||
|
||||
public WeightedRandomModel(List<ResourceLocation> locations, List<IModel> models, List<Variant> variants, IModelState defaultState) {
|
||||
this.locations.addAll(locations);
|
||||
this.models.addAll(models);
|
||||
this.variants = variants;
|
||||
this.defaultState = defaultState;
|
||||
for (IModel model : models) {
|
||||
textures.addAll(model.getTextures());
|
||||
}
|
||||
}
|
||||
|
||||
public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception {
|
||||
this.variants = variants.getVariantList();
|
||||
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
|
||||
for (Variant v : this.variants) {
|
||||
ResourceLocation loc = v.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
/*
|
||||
* Vanilla eats this, which makes it only show variants that have models.
|
||||
* But that doesn't help debugging, so throw the exception
|
||||
*/
|
||||
IModel model;
|
||||
if (loc.equals(new ModelResourceLocation("builtin/missing", "missing"))) {
|
||||
// explicit missing location, happens if blockstate has "model"=null
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
} else {
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
}
|
||||
|
||||
// FIXME: is this the place? messes up dependency and texture resolution
|
||||
model = v.process(model);
|
||||
for (ResourceLocation location : model.getDependencies()) {
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
//FMLLog.getLogger().error("Exception resolving indirect dependencies for model" + loc, e);
|
||||
textures.addAll(model.getTextures()); // Kick this, just in case.
|
||||
|
||||
models.add(model);
|
||||
builder.add(Pair.of(model, v.getState()));
|
||||
}
|
||||
|
||||
if (models.size() == 0) { //If all variants are missing, add one with the missing model and default rotation.
|
||||
// FIXME: log this?
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.of(missing, TRSRTransformation.identity()));
|
||||
}
|
||||
|
||||
defaultState = new MultiModelState(builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return ImmutableList.copyOf(locations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
return ImmutableSet.copyOf(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
if (variants.size() == 1) {
|
||||
IModel model = models.get(0);
|
||||
return model.bake(MultiModelState.getPartState(state, model, 0), format, bakedTextureGetter);
|
||||
}
|
||||
WeightedBakedModel.Builder builder = new WeightedBakedModel.Builder();
|
||||
for (int i = 0; i < variants.size(); i++) {
|
||||
IModel model = models.get(i);
|
||||
builder.add(model.bake(MultiModelState.getPartState(state, model, i), format, bakedTextureGetter), variants.get(i).getWeight());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures) {
|
||||
List<IModel> models = new ArrayList<>();
|
||||
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
|
||||
for (Variant v : this.variants) {
|
||||
ResourceLocation loc = v.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
IModel model;
|
||||
if (loc.equals(new ModelResourceLocation("builtin/missing", "missing"))) {
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
} else {
|
||||
try {
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
model = v.process(model);
|
||||
for (ResourceLocation location : model.getDependencies()) {
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
|
||||
if (model instanceof MultiModel) {
|
||||
IModel base = ObfuscationReflectionHelper.getPrivateValue(MultiModel.class, (MultiModel) model, 1);
|
||||
Map<String, Pair<IModel, IModelState>> parts = ObfuscationReflectionHelper.getPrivateValue(MultiModel.class, (MultiModel) model, 3);
|
||||
|
||||
ImmutableMap.Builder<String, Pair<IModel, IModelState>> partBuilder = new ImmutableMap.Builder<>();
|
||||
IModel retexturedModel = ModelProcessingHelper.retexture(base, textures);
|
||||
for (Entry<String, Pair<IModel, IModelState>> part : parts.entrySet()) {
|
||||
partBuilder.put(part.getKey(), Pair.of(ModelProcessingHelper.retexture(part.getValue().getLeft(), textures), part.getValue().getRight()));
|
||||
}
|
||||
|
||||
ObfuscationReflectionHelper.setPrivateValue(MultiModel.class, (MultiModel) model, retexturedModel, 1);
|
||||
ObfuscationReflectionHelper.setPrivateValue(MultiModel.class, (MultiModel) model, partBuilder.build(), 3);
|
||||
}
|
||||
model = ModelProcessingHelper.retexture(model, textures);
|
||||
|
||||
models.add(model);
|
||||
builder.add(Pair.of(model, v.getState()));
|
||||
}
|
||||
|
||||
if (models.size() == 0) {
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.of(missing, TRSRTransformation.identity()));
|
||||
}
|
||||
return new WeightedRandomModel(locations, models, variants, new MultiModelState(builder.build()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ public class WoodTextures {
|
||||
|
||||
public static void deserializeFile(IResourceManager resourceManager) {
|
||||
try {
|
||||
InputStream stream = resourceManager.getResource(new ResourceLocation("forestry:textures/woodTextures.json")).getInputStream();
|
||||
InputStream stream = resourceManager
|
||||
.getResource(new ResourceLocation("forestry:textures/woodTextures.json")).getInputStream();
|
||||
JsonReader reader = null;
|
||||
try {
|
||||
reader = new JsonReader(new BufferedReader(new InputStreamReader(stream)));
|
||||
@@ -43,7 +44,8 @@ public class WoodTextures {
|
||||
for (JsonElement eleEntry : ele.getAsJsonArray()) {
|
||||
if (eleEntry.isJsonObject()) {
|
||||
JsonObject obj = eleEntry.getAsJsonObject();
|
||||
if (!obj.has("kind") || !obj.get("kind").isJsonPrimitive() || !obj.get("kind").getAsJsonPrimitive().isString()) {
|
||||
if (!obj.has("kind") || !obj.get("kind").isJsonPrimitive()
|
||||
|| !obj.get("kind").getAsJsonPrimitive().isString()) {
|
||||
continue;
|
||||
}
|
||||
String kind = obj.get("kind").getAsString();
|
||||
@@ -97,24 +99,25 @@ public class WoodTextures {
|
||||
for (Entry<String, String> location : locations.entrySet()) {
|
||||
String texture = location.getValue();
|
||||
switch (texture) {
|
||||
case "plank":
|
||||
texture = woodType.getPlankTexture();
|
||||
break;
|
||||
case "bark":
|
||||
texture = woodType.getBarkTexture();
|
||||
break;
|
||||
case "heart":
|
||||
texture = woodType.getHeartTexture();
|
||||
break;
|
||||
case "doorUp":
|
||||
texture = woodType.getDoorUpperTexture();
|
||||
break;
|
||||
case "doorLow":
|
||||
texture = woodType.getDoorLowerTexture();
|
||||
break;
|
||||
default:
|
||||
builder.put(location.getKey(), texture.replace("%woodType", woodType.getName().toLowerCase(Locale.ENGLISH)));
|
||||
continue;
|
||||
case "plank":
|
||||
texture = woodType.getPlankTexture();
|
||||
break;
|
||||
case "bark":
|
||||
texture = woodType.getBarkTexture();
|
||||
break;
|
||||
case "heart":
|
||||
texture = woodType.getHeartTexture();
|
||||
break;
|
||||
case "doorUp":
|
||||
texture = woodType.getDoorUpperTexture();
|
||||
break;
|
||||
case "doorLow":
|
||||
texture = woodType.getDoorLowerTexture();
|
||||
break;
|
||||
default:
|
||||
builder.put(location.getKey(),
|
||||
texture.replace("%woodType", woodType.getName().toLowerCase(Locale.ENGLISH)));
|
||||
continue;
|
||||
}
|
||||
builder.put(location.getKey(), texture);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.proxy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forestry.api.arboriculture.IWoodItemMeshDefinition;
|
||||
import forestry.api.arboriculture.IWoodStateMapper;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
@@ -23,11 +26,14 @@ import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.blocks.BlockArbSlab;
|
||||
import forestry.arboriculture.blocks.BlockDecorativeLeaves;
|
||||
import forestry.arboriculture.blocks.WoodTypeStateMapper;
|
||||
import forestry.arboriculture.models.ModelDecorativeLeaves;
|
||||
import forestry.arboriculture.models.ModelLeaves;
|
||||
import forestry.arboriculture.models.MultipartModel;
|
||||
import forestry.arboriculture.models.WoodModelLoader;
|
||||
import forestry.arboriculture.models.WoodTextures;
|
||||
import forestry.core.models.BlockModelEntry;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.models.SimpleRetexturedModel;
|
||||
import forestry.core.models.WoodModelEntry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -38,6 +44,7 @@ import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Multipart;
|
||||
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -54,13 +61,16 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ProxyArboricultureClient extends ProxyArboriculture {
|
||||
private static final Set<WoodModelEntry> woodModelEntrys = new HashSet<>();
|
||||
private static final Map<IWoodTyped, IWoodStateMapper> stateMappers = Maps.newIdentityHashMap();
|
||||
private static final Map<Item, IWoodItemMeshDefinition> shapers = Maps.newHashMap();
|
||||
|
||||
@Override
|
||||
public void initializeModels() {
|
||||
{
|
||||
ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:leaves");
|
||||
ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:leaves", "inventory");
|
||||
BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelLeaves(), PluginArboriculture.getBlocks().leaves);
|
||||
BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation,
|
||||
new ModelLeaves(), PluginArboriculture.getBlocks().leaves);
|
||||
Proxies.render.registerBlockModel(blockModelIndex);
|
||||
}
|
||||
|
||||
@@ -68,7 +78,8 @@ public class ProxyArboricultureClient extends ProxyArboriculture {
|
||||
String resourceName = "forestry:leaves.decorative." + leaves.getBlockNumber();
|
||||
ModelResourceLocation blockModelLocation = new ModelResourceLocation(resourceName);
|
||||
ModelResourceLocation itemModeLocation = new ModelResourceLocation(resourceName, "inventory");
|
||||
BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModeLocation, new ModelDecorativeLeaves(), leaves);
|
||||
BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModeLocation,
|
||||
new ModelDecorativeLeaves(), leaves);
|
||||
Proxies.render.registerBlockModel(blockModelIndex);
|
||||
}
|
||||
|
||||
@@ -81,63 +92,79 @@ public class ProxyArboricultureClient extends ProxyArboriculture {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerWoodMeshDefinition(Item item, IWoodItemMeshDefinition definition) {
|
||||
ModelManager.getInstance().registerItemModel(item, definition);
|
||||
shapers.put(item, definition);
|
||||
}
|
||||
|
||||
public static void registerWoodStateMapper(Block block, IWoodStateMapper stateMapper) {
|
||||
if (block instanceof IWoodTyped) {
|
||||
IWoodTyped woodTyped = (IWoodTyped) block;
|
||||
Proxies.render.registerStateMapper(block, stateMapper);
|
||||
stateMappers.put(woodTyped, stateMapper);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public <T extends Block & IWoodTyped> void onModelBake(ModelBakeEvent event) {
|
||||
WoodModelLoader.INSTANCE.isRegistered = true;
|
||||
WoodModelLoader.INSTANCE.isEnabled = true;
|
||||
IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
||||
Minecraft minecraft = Proxies.common.getClientInstance();
|
||||
Map<ResourceLocation, Exception> loadingExceptions = ObfuscationReflectionHelper.getPrivateValue(ModelLoader.class, event.getModelLoader(), 2);
|
||||
|
||||
if (minecraft.getBlockRendererDispatcher() != null) {
|
||||
BlockStateMapper stateMapper = minecraft.getBlockRendererDispatcher().getBlockModelShapes().getBlockStateMapper();
|
||||
Map<Item, ItemMeshDefinition> definitions = ObfuscationReflectionHelper.getPrivateValue(ItemModelMesher.class, minecraft.getRenderItem().getItemModelMesher(), 2);
|
||||
Map<Block, IStateMapper> blockStateMap = ObfuscationReflectionHelper.getPrivateValue(BlockStateMapper.class, stateMapper, 0);
|
||||
for (WoodModelEntry<T> entry : woodModelEntrys) {
|
||||
T woodTyped = entry.woodTyped;
|
||||
WoodBlockKind woodKind = woodTyped.getBlockKind();
|
||||
IWoodStateMapper woodMapper = stateMappers.get(woodTyped);
|
||||
|
||||
for (WoodModelEntry<T> entry : woodModelEntrys) {
|
||||
T woodTyped = entry.woodTyped;
|
||||
WoodBlockKind woodKind = woodTyped.getBlockKind();
|
||||
|
||||
IStateMapper mapper = blockStateMap.get(woodTyped);
|
||||
if (mapper instanceof IWoodStateMapper) {
|
||||
IWoodStateMapper woodMapper = (IWoodStateMapper) mapper;
|
||||
try {
|
||||
for (IBlockState state : woodTyped.getBlockState().getValidStates()) {
|
||||
IWoodType woodType;
|
||||
ItemStack itemStack;
|
||||
if (entry.withVariants) {
|
||||
int meta = woodTyped.getMetaFromState(state);
|
||||
woodType = woodTyped.getWoodType(meta);
|
||||
itemStack = new ItemStack(woodTyped, 1, meta);
|
||||
} else {
|
||||
woodType = woodTyped.getWoodType(0);
|
||||
itemStack = new ItemStack(woodTyped);
|
||||
}
|
||||
ImmutableMap<String, String> customTextures = WoodTextures.getLocations(woodType, woodKind);
|
||||
if (woodKind.retextureItem) {
|
||||
ItemMeshDefinition definition = definitions.get(itemStack.getItem());
|
||||
if (definition instanceof IWoodItemMeshDefinition) {
|
||||
IWoodItemMeshDefinition woodDefinition = (IWoodItemMeshDefinition) definition;
|
||||
IModel basicItemModel = ModelLoaderRegistry.getModel(woodDefinition.getDefaultModelLocation(itemStack));
|
||||
ModelResourceLocation basicItemLocation = definition.getModelLocation(itemStack);
|
||||
|
||||
registry.putObject(basicItemLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicItemModel, woodType, customTextures)));
|
||||
}
|
||||
}
|
||||
IModel basicModel = ModelLoaderRegistry.getModel(woodMapper.getDefaultModelResourceLocation(state));
|
||||
ModelResourceLocation basicLocation = woodMapper.getModelLocation(state);
|
||||
if (loadingExceptions.containsKey(basicLocation)) {
|
||||
loadingExceptions.remove(basicLocation);
|
||||
}
|
||||
registry.putObject(basicLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicModel, woodType, customTextures)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (IBlockState blockState : woodTyped.getBlockState().getValidStates()) {
|
||||
IWoodType woodType;
|
||||
ItemStack itemStack;
|
||||
if (entry.withVariants) {
|
||||
int meta = woodTyped.getMetaFromState(blockState);
|
||||
woodType = woodTyped.getWoodType(meta);
|
||||
itemStack = new ItemStack(woodTyped, 1, meta);
|
||||
} else {
|
||||
woodType = woodTyped.getWoodType(0);
|
||||
itemStack = new ItemStack(woodTyped);
|
||||
}
|
||||
IWoodItemMeshDefinition definition = shapers.get(itemStack.getItem());
|
||||
ImmutableMap<String, String> textures = WoodTextures.getLocations(woodType, woodKind);
|
||||
if (definition != null) {
|
||||
retextureItemModel(registry, textures, woodType, woodKind, itemStack, definition);
|
||||
}
|
||||
if (woodMapper != null) {
|
||||
retexturBlockModel(registry, textures, woodType, woodKind, blockState, woodMapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void retextureItemModel(IRegistry<ModelResourceLocation, IBakedModel> registry,
|
||||
ImmutableMap<String, String> textures, IWoodType woodType, WoodBlockKind woodKind, ItemStack itemStack,
|
||||
IWoodItemMeshDefinition woodDefinition) {
|
||||
if (woodKind != WoodBlockKind.DOOR) {
|
||||
IModel basicItemModel = ModelLoaderRegistry
|
||||
.getModelOrMissing(woodDefinition.getDefaultModelLocation(itemStack));
|
||||
ModelResourceLocation basicItemLocation = woodDefinition.getModelLocation(itemStack);
|
||||
|
||||
registry.putObject(basicItemLocation,
|
||||
new SimpleRetexturedModel(woodKind.retextureModel(basicItemModel, woodType, textures)));
|
||||
}
|
||||
}
|
||||
|
||||
private void retexturBlockModel(IRegistry<ModelResourceLocation, IBakedModel> registry,
|
||||
ImmutableMap<String, String> textures, IWoodType woodType, WoodBlockKind woodKind, IBlockState blockState,
|
||||
IWoodStateMapper woodMapper) {
|
||||
IModel basicModel = ModelLoaderRegistry
|
||||
.getModelOrMissing(woodMapper.getDefaultModelResourceLocation(blockState));
|
||||
if (basicModel instanceof MultipartModel) {
|
||||
MultipartModel multipartModel = (MultipartModel) basicModel;
|
||||
Multipart multipart = multipartModel.getMultipart();
|
||||
multipart.setStateContainer(blockState.getBlock().getBlockState());
|
||||
}
|
||||
ModelResourceLocation basicLocation = woodMapper.getModelLocation(blockState);
|
||||
registry.putObject(basicLocation,
|
||||
new SimpleRetexturedModel(woodKind.retextureModel(basicModel, woodType, textures)));
|
||||
|
||||
loadingExceptions.putAll(WoodModelLoader.loadingExceptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,12 +12,20 @@ package forestry.core.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -25,7 +33,9 @@ import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlock;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.SimpleModelState;
|
||||
@@ -33,18 +43,20 @@ import net.minecraftforge.client.model.IPerspectiveAwareModel.MapWrapper;
|
||||
|
||||
public class ModelUtil {
|
||||
|
||||
private static final Map<ResourceLocation, ModelBlockDefinition> blockDefinitions = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* @return The model from the item of the stack.
|
||||
*/
|
||||
@Nullable
|
||||
public static IBakedModel getModel(ItemStack stack) {
|
||||
RenderItem renderItem = Proxies.common.getClientInstance().getRenderItem();
|
||||
if(renderItem == null || renderItem.getItemModelMesher() == null){
|
||||
if (renderItem == null || renderItem.getItemModelMesher() == null) {
|
||||
return null;
|
||||
}
|
||||
return renderItem.getItemModelMesher().getItemModel(stack);
|
||||
}
|
||||
|
||||
|
||||
public static SimpleModelState loadModelState(ResourceLocation location) {
|
||||
return new SimpleModelState(MapWrapper.getTransforms(loadTransformFromJson(location)));
|
||||
}
|
||||
@@ -57,11 +69,61 @@ public class ModelUtil {
|
||||
}
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
private static Reader getReaderForResource(ResourceLocation location) throws IOException {
|
||||
ResourceLocation file = new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + ".json");
|
||||
ResourceLocation file = new ResourceLocation(location.getResourceDomain(),
|
||||
location.getResourcePath() + ".json");
|
||||
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(file);
|
||||
return new BufferedReader(new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
public static ModelBlockDefinition getModelBlockDefinition(ResourceLocation location) {
|
||||
try {
|
||||
ResourceLocation resourcelocation = getBlockstateLocation(location);
|
||||
return blockDefinitions.computeIfAbsent(resourcelocation,
|
||||
k -> loadMultipartMBD(location, resourcelocation));
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
return new ModelBlockDefinition(new ArrayList<>());
|
||||
}
|
||||
|
||||
private static ResourceLocation getBlockstateLocation(ResourceLocation location) {
|
||||
return new ResourceLocation(location.getResourceDomain(),
|
||||
"blockstates/" + location.getResourcePath() + ".json");
|
||||
}
|
||||
|
||||
private static ModelBlockDefinition loadMultipartMBD(ResourceLocation location, ResourceLocation fileIn) {
|
||||
List<ModelBlockDefinition> list = Lists.newArrayList();
|
||||
Minecraft mc = Proxies.common.getClientInstance();
|
||||
IResourceManager manager = mc.getResourceManager();
|
||||
|
||||
try {
|
||||
for (IResource resource : manager.getAllResources(fileIn)) {
|
||||
list.add(loadModelBlockDefinition(location, resource));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Encountered an exception when loading model definition of model " + fileIn, e);
|
||||
}
|
||||
|
||||
return new ModelBlockDefinition(list);
|
||||
}
|
||||
|
||||
private static ModelBlockDefinition loadModelBlockDefinition(ResourceLocation location, IResource resource) {
|
||||
InputStream inputStream = null;
|
||||
ModelBlockDefinition definition;
|
||||
|
||||
try {
|
||||
inputStream = resource.getInputStream();
|
||||
definition = ModelBlockDefinition.parseFromReader(new InputStreamReader(inputStream, Charsets.UTF_8));
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException("Encountered an exception when loading model definition of \'" + location
|
||||
+ "\' from: \'" + resource.getResourceLocation() + "\' in resourcepack: \'"
|
||||
+ resource.getResourcePackName() + "\'", exception);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
private static final String CONFIG_CATEGORY = "lepidopterology";
|
||||
public static int spawnConstraint = 100;
|
||||
public static int entityConstraint = 1000;
|
||||
public static int maxDistance = 1600;
|
||||
public static int maxDistance = 256;
|
||||
private static boolean allowPollination = true;
|
||||
public static final Map<String, Float> spawnRaritys = Maps.newHashMap();
|
||||
private static boolean spawnButterflysFromLeaves = true;
|
||||
@@ -133,7 +133,6 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
proxy.preInitializeRendering();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getDependencyUids() {
|
||||
Set<String> dependencyUids = super.getDependencyUids();
|
||||
@@ -148,7 +147,8 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
PluginCore.rootCommand.addChildCommand(new CommandButterfly());
|
||||
|
||||
ResourceLocation butterflyResourceLocation = new ResourceLocation(Constants.MOD_ID, "butterflyGE");
|
||||
EntityUtil.registerEntity(butterflyResourceLocation, EntityButterfly.class, "butterflyGE", 0, 0x000000, 0xffffff, 50, 1, true);
|
||||
EntityUtil.registerEntity(butterflyResourceLocation, EntityButterfly.class, "butterflyGE", 0, 0x000000,
|
||||
0xffffff, 50, 1, true);
|
||||
|
||||
MothDefinition.initMoths();
|
||||
ButterflyDefinition.initButterflies();
|
||||
@@ -162,7 +162,8 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
TreeManager.treeRoot.registerLeafTickHandler(new ButterflySpawner());
|
||||
}
|
||||
|
||||
RecipeSorter.register("forestry:lepidopterologymating", MatingRecipe.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless");
|
||||
RecipeSorter.register("forestry:lepidopterologymating", MatingRecipe.class, RecipeSorter.Category.SHAPELESS,
|
||||
"before:minecraft:shapeless");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,7 +173,8 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
|
||||
public void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ,
|
||||
boolean hasVillageGenerated) {
|
||||
if (generateCocoons) {
|
||||
if (generateCocoonsAmount > 0.0) {
|
||||
CocoonDecorator.decorateCocoons(chunkGenerator, world, rand, chunkX, chunkZ, hasVillageGenerated);
|
||||
@@ -194,15 +196,18 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
spawnConstraint = config.getIntLocalized("butterfly.entities", "spawn.limit", spawnConstraint, 0, 500);
|
||||
entityConstraint = config.getIntLocalized("butterfly.entities", "maximum", entityConstraint, 0, 5000);
|
||||
maxDistance = config.getIntLocalized("butterfly.entities", "maxDistance", maxDistance, 0, 1600);
|
||||
maxDistance = config.getIntLocalized("butterfly.entities", "maxDistance", maxDistance, 0, 256);
|
||||
allowPollination = config.getBooleanLocalized("butterfly.entities", "pollination", allowPollination);
|
||||
spawnButterflysFromLeaves = config.getBooleanLocalized("butterfly.entities", "spawn.leaves", spawnButterflysFromLeaves);
|
||||
spawnButterflysFromLeaves = config.getBooleanLocalized("butterfly.entities", "spawn.leaves",
|
||||
spawnButterflysFromLeaves);
|
||||
|
||||
generateCocoons = config.getBooleanLocalized("butterfly.cocoons", "generate", generateCocoons);
|
||||
generateCocoonsAmount = config.getFloatLocalized("butterfly.cocoons", "generate.amount", generateCocoonsAmount, 0.0f, 10.0f);
|
||||
generateCocoonsAmount = config.getFloatLocalized("butterfly.cocoons", "generate.amount", generateCocoonsAmount,
|
||||
0.0f, 10.0f);
|
||||
|
||||
serumChance = config.getFloatLocalized("butterfly.cocoons", "serum", serumChance, 0.0f, 100.0f);
|
||||
secondSerumChance = config.getFloatLocalized("butterfly.cocoons", "second.serum", secondSerumChance, 0.0f, 100.0f);
|
||||
secondSerumChance = config.getFloatLocalized("butterfly.cocoons", "second.serum", secondSerumChance, 0.0f,
|
||||
100.0f);
|
||||
|
||||
parseRarity(config);
|
||||
parseCooconLoots(config);
|
||||
@@ -277,8 +282,10 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
cocoon.getCocoonLoot().clear();
|
||||
cocoon.getCocoonLoot().putAll(cooconLoot);
|
||||
cocoon.clearLoot();
|
||||
for (Entry<ItemStack, Float> entry : cocoon.getCocoonLoot().entrySet()) {
|
||||
cocoon.addLoot(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,13 +295,8 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
CraftingManager.getInstance().getRecipeList().add(new MatingRecipe());
|
||||
|
||||
RecipeUtil.addRecipe(blocks.butterflyChest,
|
||||
" # ",
|
||||
"XYX",
|
||||
"XXX",
|
||||
'#', "blockGlass",
|
||||
'X', new ItemStack(items.butterflyGE, 1, OreDictionary.WILDCARD_VALUE),
|
||||
'Y', "chestWood");
|
||||
RecipeUtil.addRecipe(blocks.butterflyChest, " # ", "XYX", "XXX", '#', "blockGlass", 'X',
|
||||
new ItemStack(items.butterflyGE, 1, OreDictionary.WILDCARD_VALUE), 'Y', "chestWood");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,11 +49,12 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
private static final PropertyCocoon COCOON = AlleleButterflyCocoon.COCOON;
|
||||
|
||||
public BlockCocoon() {
|
||||
super(new MaterialCocoon());
|
||||
super(MaterialCocoon.INSTANCE);
|
||||
setTickRandomly(true);
|
||||
setSoundType(SoundType.GROUND);
|
||||
setCreativeTab(null);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(COCOON, ButterflyAlleles.cocoonDefault).withProperty(AlleleButterflyCocoon.AGE, 0));
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(COCOON, ButterflyAlleles.cocoonDefault)
|
||||
.withProperty(AlleleButterflyCocoon.AGE, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +67,8 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileCocoon cocoon = TileUtil.getTile(world, pos, TileCocoon.class);
|
||||
if (cocoon != null) {
|
||||
state = state.withProperty(COCOON, cocoon.getCaterpillar().getGenome().getCocoon()).withProperty(AlleleButterflyCocoon.AGE, cocoon.getAge());
|
||||
state = state.withProperty(COCOON, cocoon.getCaterpillar().getGenome().getCocoon())
|
||||
.withProperty(AlleleButterflyCocoon.AGE, cocoon.getAge());
|
||||
}
|
||||
return super.getActualState(state, world, pos);
|
||||
}
|
||||
@@ -80,7 +82,7 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
//To delete the error message
|
||||
// To delete the error message
|
||||
manager.registerItemModel(item, 0, "cocoon_late");
|
||||
}
|
||||
|
||||
@@ -105,9 +107,9 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.rand.nextFloat() > 0.1) {
|
||||
return;
|
||||
}
|
||||
// if (rand.nextFloat() > 0.25) {
|
||||
// return;
|
||||
// }
|
||||
tileCocoon.onBlockTick();
|
||||
}
|
||||
|
||||
@@ -135,7 +137,8 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
|
||||
EntityPlayer player) {
|
||||
TileCocoon tile = TileUtil.getTile(world, pos, TileCocoon.class);
|
||||
if (tile == null) {
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
@@ -44,13 +44,14 @@ public class BlockSolidCocoon extends Block implements ITileEntityProvider, ISta
|
||||
private static final PropertyCocoon COCOON = AlleleButterflyCocoon.COCOON;
|
||||
|
||||
public BlockSolidCocoon() {
|
||||
super(new MaterialCocoon());
|
||||
super(MaterialCocoon.INSTANCE);
|
||||
setHarvestLevel("scoop", 0);
|
||||
setHardness(0.5F);
|
||||
setTickRandomly(true);
|
||||
setSoundType(SoundType.GROUND);
|
||||
setCreativeTab(null);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(COCOON, ButterflyAlleles.cocoonDefault).withProperty(AlleleButterflyCocoon.AGE, 0));
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(COCOON, ButterflyAlleles.cocoonDefault)
|
||||
.withProperty(AlleleButterflyCocoon.AGE, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +64,8 @@ public class BlockSolidCocoon extends Block implements ITileEntityProvider, ISta
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileCocoon cocoon = TileUtil.getTile(world, pos, TileCocoon.class);
|
||||
if (cocoon != null) {
|
||||
state = state.withProperty(COCOON, cocoon.getCaterpillar().getGenome().getCocoon()).withProperty(AlleleButterflyCocoon.AGE, cocoon.getAge());
|
||||
state = state.withProperty(COCOON, cocoon.getCaterpillar().getGenome().getCocoon())
|
||||
.withProperty(AlleleButterflyCocoon.AGE, cocoon.getAge());
|
||||
}
|
||||
return super.getActualState(state, world, pos);
|
||||
}
|
||||
@@ -77,7 +79,7 @@ public class BlockSolidCocoon extends Block implements ITileEntityProvider, ISta
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
//To delete the error message
|
||||
// To delete the error message
|
||||
manager.registerItemModel(item, 0, "cocoon_late");
|
||||
}
|
||||
|
||||
@@ -92,7 +94,8 @@ public class BlockSolidCocoon extends Block implements ITileEntityProvider, ISta
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player,
|
||||
boolean willHarvest) {
|
||||
if (canHarvestBlock(world, pos, player)) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
|
||||
@@ -15,10 +15,13 @@ import net.minecraft.block.material.Material;
|
||||
|
||||
public class MaterialCocoon extends Material {
|
||||
|
||||
public MaterialCocoon() {
|
||||
public static final Material INSTANCE = new MaterialCocoon();
|
||||
|
||||
private MaterialCocoon() {
|
||||
super(MapColor.CLOTH);
|
||||
|
||||
setRequiresTool();
|
||||
setBurning();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.genetics.alleles;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -50,12 +51,23 @@ public class AlleleButterflyCocoon extends AlleleCategorized implements IAlleleB
|
||||
|
||||
@Override
|
||||
public ModelResourceLocation getCocoonItemModel(int age) {
|
||||
return new ModelResourceLocation(Constants.MOD_ID + ":lepidopterology/cocoons/cocoon_" + name + "_" + getAgeKey(age), "inventory");
|
||||
return new ModelResourceLocation(
|
||||
Constants.MOD_ID + ":lepidopterology/cocoons/cocoon_" + name + "_" + getAgeKey(age), "inventory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLoot() {
|
||||
this.loot.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLoot(ItemStack loot, float chance) {
|
||||
this.loot.put(loot, chance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ItemStack, Float> getCocoonLoot() {
|
||||
return loot;
|
||||
return Collections.unmodifiableMap(loot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,8 @@ import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButterflySpecies, IAlleleButterflySpeciesBuilder {
|
||||
public class AlleleButterflySpecies extends AlleleSpecies
|
||||
implements IAlleleButterflySpecies, IAlleleButterflySpeciesBuilder {
|
||||
private final String texture;
|
||||
private final String modID;
|
||||
private final Color serumColour;
|
||||
@@ -52,7 +53,9 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
|
||||
private final Map<ItemStack, Float> butterflyLoot = new HashMap<>();
|
||||
private final Map<ItemStack, Float> caterpillarLoot = new HashMap<>();
|
||||
|
||||
public AlleleButterflySpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean isDominant, IClassification branch, String binomial, Color serumColour) {
|
||||
public AlleleButterflySpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription,
|
||||
String modID, String texturePath, boolean isDominant, IClassification branch, String binomial,
|
||||
Color serumColour) {
|
||||
super(uid, unlocalizedName, authority, unlocalizedDescription, isDominant, branch, binomial);
|
||||
this.serumColour = serumColour;
|
||||
|
||||
@@ -150,7 +153,8 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
|
||||
public NonNullList<ItemStack> getResearchBounty(World world, GameProfile researcher, IIndividual individual,
|
||||
int bountyLevel) {
|
||||
ItemStack serum = getRoot().getMemberStack(individual.copy(), EnumFlutterType.SERUM);
|
||||
NonNullList<ItemStack> bounty = NonNullList.create();
|
||||
bounty.add(serum);
|
||||
|
||||
@@ -8,6 +8,7 @@ import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.IAlleleButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IAlleleButterflyEffect;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -19,10 +20,8 @@ public class ButterflyAlleles {
|
||||
public static final IAlleleButterflyEffect butterflyNone = new AlleleButterflyEffectNone();
|
||||
|
||||
static {
|
||||
cocoonAlleles = Arrays.asList(
|
||||
cocoonDefault = new AlleleButterflyCocoon("default", false),
|
||||
cocoonSilk = new AlleleButterflyCocoon("silk", false)
|
||||
);
|
||||
cocoonAlleles = Arrays.asList(cocoonDefault = new AlleleButterflyCocoon("default", false),
|
||||
cocoonSilk = new AlleleButterflyCocoon("silk", false));
|
||||
}
|
||||
|
||||
public static void registerCocoonAlleles() {
|
||||
@@ -36,13 +35,13 @@ public class ButterflyAlleles {
|
||||
}
|
||||
|
||||
public static void createLoot() {
|
||||
cocoonDefault.getCocoonLoot().put(new ItemStack(Items.STRING, 2), 1F);
|
||||
cocoonDefault.getCocoonLoot().put(new ItemStack(Items.STRING), 0.75F);
|
||||
cocoonDefault.getCocoonLoot().put(new ItemStack(Items.STRING, 3), 0.25F);
|
||||
cocoonDefault.addLoot(new ItemStack(Items.STRING, 2), 1F);
|
||||
cocoonDefault.addLoot(new ItemStack(Items.STRING), 0.75F);
|
||||
cocoonDefault.addLoot(new ItemStack(Items.STRING, 3), 0.25F);
|
||||
|
||||
cocoonSilk.getCocoonLoot().put(new ItemStack(PluginCore.getItems().craftingMaterial, 3, 2), 0.75F);
|
||||
cocoonSilk.getCocoonLoot().put(new ItemStack(PluginCore.getItems().craftingMaterial, 2, 2), 0.25F);
|
||||
ItemRegistryCore itemRegistry = PluginCore.getItems();
|
||||
cocoonSilk.addLoot(new ItemStack(itemRegistry.craftingMaterial, 3, 2), 0.75F);
|
||||
cocoonSilk.addLoot(new ItemStack(itemRegistry.craftingMaterial, 2, 2), 0.25F);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -145,7 +145,9 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtil.spawnEntity(entityItem.world, new EntityButterfly(entityItem.world, butterfly, entityItem.getPosition()), entityItem.posX, entityItem.posY, entityItem.posZ);
|
||||
EntityUtil.spawnEntity(entityItem.world,
|
||||
new EntityButterfly(entityItem.world, butterfly, entityItem.getPosition()), entityItem.posX,
|
||||
entityItem.posY, entityItem.posZ);
|
||||
if (!entityItem.getEntityItem().isEmpty()) {
|
||||
entityItem.getEntityItem().shrink(1);
|
||||
} else {
|
||||
@@ -159,24 +161,25 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
switch (this.type) {
|
||||
case CATERPILLAR:
|
||||
manager.registerItemModel(item, 0, "caterpillar");
|
||||
break;
|
||||
case BUTTERFLY:
|
||||
manager.registerItemModel(item, 0, "butterflyGE");
|
||||
break;
|
||||
case COCOON:
|
||||
manager.registerItemModel(item, new CocoonMeshDefinition());
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleButterflyCocoon) {
|
||||
for (int age = 0; age < 3; age++) {
|
||||
ModelBakery.registerItemVariants(this, ((IAlleleButterflyCocoon) allele).getCocoonItemModel(age));
|
||||
}
|
||||
case CATERPILLAR:
|
||||
manager.registerItemModel(item, 0, "caterpillar");
|
||||
break;
|
||||
case BUTTERFLY:
|
||||
manager.registerItemModel(item, 0, "butterflyGE");
|
||||
break;
|
||||
case COCOON:
|
||||
manager.registerItemModel(item, new CocoonMeshDefinition());
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleButterflyCocoon) {
|
||||
for (int age = 0; age < 3; age++) {
|
||||
ModelBakery.registerItemVariants(this,
|
||||
((IAlleleButterflyCocoon) allele).getCocoonItemModel(age));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
manager.registerItemModel(item, 0, "liquids/jar");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
manager.registerItemModel(item, 0, "liquids/jar");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +198,10 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
if (worldIn.isRemote) {
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing,
|
||||
float hitX, float hitY, float hitZ) {
|
||||
if (world.isRemote) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
@@ -206,16 +209,17 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
|
||||
IButterfly flutter = ButterflyManager.butterflyRoot.getMember(stack);
|
||||
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
IBlockState blockState = worldIn.getBlockState(pos);
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (type == EnumFlutterType.COCOON) {
|
||||
NBTTagCompound tagCompound = stack.getTagCompound();
|
||||
int age = tagCompound.getInteger(NBT_AGE);
|
||||
|
||||
// x, y, z are the coordinates of the block "hit", can thus either be the soil or tall grass, etc.
|
||||
// x, y, z are the coordinates of the block "hit", can thus either
|
||||
// be the soil or tall grass, etc.
|
||||
int yShift;
|
||||
if (!BlockUtil.isReplaceableBlock(blockState, worldIn, pos)) {
|
||||
if (!worldIn.isAirBlock(pos.down())) {
|
||||
if (!BlockUtil.isReplaceableBlock(blockState, world, pos)) {
|
||||
if (!world.isAirBlock(pos.down())) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
yShift = 1;
|
||||
@@ -224,25 +228,14 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
}
|
||||
BlockPos posS = pos.add(0, -yShift, 0);
|
||||
|
||||
IButterflyNursery nursery = null;
|
||||
|
||||
if (tileEntity instanceof IButterflyNursery) {
|
||||
nursery = (IButterflyNursery) tileEntity;
|
||||
} else {
|
||||
IIndividual treeLeave = GeneticsUtil.getPollen(worldIn, pos);
|
||||
|
||||
if (treeLeave != null && treeLeave instanceof ITree) {
|
||||
if (((ITree) treeLeave).setLeaves(worldIn, player.getGameProfile(), pos)) {
|
||||
nursery = (IButterflyNursery) worldIn.getTileEntity(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(world, pos, player);
|
||||
if (nursery != null) {
|
||||
if (nursery.canNurse(flutter)) {
|
||||
nursery.setCaterpillar(flutter);
|
||||
if (ButterflyManager.butterflyRoot.plantCocoon(worldIn, nursery, player.getGameProfile(), age)) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, worldIn.getBlockState(posS));
|
||||
Proxies.net.sendNetworkPacket(packet, pos, worldIn);
|
||||
if (ButterflyManager.butterflyRoot.plantCocoon(world, nursery, player.getGameProfile(), age)) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos,
|
||||
world.getBlockState(posS));
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.shrink(1);
|
||||
@@ -258,25 +251,24 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
return EnumActionResult.PASS;
|
||||
} else if (type == EnumFlutterType.CATERPILLAR) {
|
||||
|
||||
if (!(tileEntity instanceof IButterflyNursery)) {
|
||||
return EnumActionResult.PASS;
|
||||
IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(world, pos, player);
|
||||
if (nursery != null) {
|
||||
if (!nursery.canNurse(flutter)) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
nursery.setCaterpillar(flutter);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK,
|
||||
PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
IButterflyNursery pollinatable = (IButterflyNursery) tileEntity;
|
||||
if (!pollinatable.canNurse(flutter)) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
pollinatable.setCaterpillar(flutter);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, worldIn);
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
} else {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
@@ -295,7 +287,6 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
if (itemstack.getTagCompound() == null) {
|
||||
@@ -303,7 +294,8 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
}
|
||||
|
||||
IButterfly individual = ButterflyManager.butterflyRoot.getMember(itemstack);
|
||||
String customKey = "for.butterflies.custom." + type.getName() + "." + individual.getGenome().getPrimary().getUnlocalizedName().replace("butterflies.species.", "");
|
||||
String customKey = "for.butterflies.custom." + type.getName() + "."
|
||||
+ individual.getGenome().getPrimary().getUnlocalizedName().replace("butterflies.species.", "");
|
||||
if (Translator.canTranslateToLocal(customKey)) {
|
||||
return Translator.translateToLocal(customKey);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
isSolid = nbttagcompound.getBoolean("isSolid");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
@@ -163,8 +162,12 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(NBTTagCompound tag) {
|
||||
int oldAge = age;
|
||||
super.handleUpdateTag(tag);
|
||||
NBTUtilForestry.readStreamableFromNbt(this, tag);
|
||||
if (oldAge != age) {
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,12 +181,15 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
maturationTime++;
|
||||
|
||||
IButterflyGenome caterpillarGenome = caterpillar.getGenome();
|
||||
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
|
||||
int caterpillarMatureTime = Math
|
||||
.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
|
||||
|
||||
if (maturationTime >= caterpillarMatureTime) {
|
||||
if (age < 2) {
|
||||
age++;
|
||||
maturationTime = 0;
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
world.notifyBlockUpdate(pos, blockState, blockState, 0);
|
||||
} else if (caterpillar.canTakeFlight(world, getPos().getX(), getPos().getY(), getPos().getZ())) {
|
||||
IGreenhouseComponent.ButterflyHatch hatch = getButterflyHatch(world, pos);
|
||||
NonNullList<ItemStack> cocoonDrops;
|
||||
@@ -203,7 +209,8 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
|
||||
@Nullable
|
||||
public ButterflyHatch getButterflyHatch(World world, BlockPos pos) {
|
||||
if (GreenhouseManager.greenhouseHelper == null || GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos) == null) {
|
||||
if (GreenhouseManager.greenhouseHelper == null
|
||||
|| GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos) == null) {
|
||||
return null;
|
||||
}
|
||||
IGreenhouseController controller = GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos);
|
||||
@@ -222,8 +229,10 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
}
|
||||
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
EntityLiving entityLiving = ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ());
|
||||
Log.trace("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
EntityLiving entityLiving = ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(),
|
||||
pos.getX(), pos.getY() + 0.1f, pos.getZ());
|
||||
Log.trace("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(),
|
||||
pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user