Java tutorial
/* * This class was created by: RANKSHANK as a part of the Arbitraria mod. * Full source can be found @ https://github.com/RANKSHANK/Arbitraria * * Arbitraria is provided in binary and source forms under the Arbitraria License. * Arbitraria License can be found in the repository @ https://github.com/RANKSHANK/Arbitraria */ package mod.rankshank.arbitraria.client.item.spraybottle; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import mod.rankshank.arbitraria.common.init.Arbitraria; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.*; import net.minecraftforge.common.model.IModelState; import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Collection; @SideOnly(Side.CLIENT) public final class ModelSprayBottleFluid implements IModelCustomData, IRetexturableModel { public static final ModelSprayBottleFluid BASE = new ModelSprayBottleFluid(null, null, null); private static final float NORTH_Z_FLUID = 0.468625f, SOUTH_Z_FLUID = 0.531375f; private final Fluid fluid; private ResourceLocation bottle, filler; public ModelSprayBottleFluid(ResourceLocation bottleLoc, ResourceLocation fillerLoc, Fluid contents) { bottle = bottleLoc == null ? Arbitraria.getRss("items/spray_empty") : bottleLoc; filler = fillerLoc == null ? Arbitraria.getRss("items/spray_fill") : fillerLoc; fluid = contents; } @Override public Collection<ResourceLocation> getDependencies() { return ImmutableList.of(); } @Override public Collection<ResourceLocation> getTextures() { ImmutableSet.Builder<ResourceLocation> bob = ImmutableSet.builder(); bob.add(filler); bob.add(bottle); return bob.build(); } @Override @SuppressWarnings({ "ConstantConditions", "Guava" }) public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper .getTransforms(state); ImmutableList.Builder<BakedQuad> bob = ImmutableList.builder(); TRSRTransformation transform = state.apply(Optional.absent()).or(TRSRTransformation.identity()); TextureAtlasSprite fluidSprite = null; if (this.bottle != null) bob.addAll(new ItemLayerModel(ImmutableList.of(this.bottle)).bake(state, format, bakedTextureGetter) .getQuads(null, null, 0L)); if (this.filler != null && this.fluid != null && (fluidSprite = bakedTextureGetter.apply(this.fluid.getStill())) != null) { TextureAtlasSprite fillerSprite = bakedTextureGetter.apply(this.filler); bob.addAll(ItemTextureQuadConverter.convertTexture(format, transform, fillerSprite, fluidSprite, 0.468625f, EnumFacing.NORTH, fluid.getColor())); bob.addAll(ItemTextureQuadConverter.convertTexture(format, transform, fillerSprite, fluidSprite, 0.531375f, EnumFacing.SOUTH, fluid.getColor())); } return new BakedSprayBottleFluid(this, bob.build(), fluidSprite, format, transformMap); } @Override public IModelState getDefaultState() { return TRSRTransformation.identity(); } @Override public IModel process(ImmutableMap<String, String> customData) { Fluid dataFluid = FluidRegistry.getFluid(customData.get("fluid")); return new ModelSprayBottleFluid(this.bottle, this.filler, dataFluid == null ? this.fluid : dataFluid); } @Override public IModel retexture(ImmutableMap<String, String> data) { return new ModelSprayBottleFluid( data.containsKey("bottle") ? new ResourceLocation(data.get("bottle")) : this.bottle, data.containsKey("filler") ? new ResourceLocation(data.get("filler")) : this.filler, this.fluid); } }