Skip to content

Commit

Permalink
backport mod version 2.0.1 to 1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
cech12 committed Aug 28, 2020
1 parent 3d16f5f commit 4639d43
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 68 deletions.
21 changes: 11 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ archivesBaseName = 'ceramicbucket'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
Expand Down Expand Up @@ -104,12 +103,11 @@ dependencies {
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft "net.minecraftforge:forge:${project.forge_version}"
implementation 'org.jetbrains:annotations:15.0'

// compile against the JEI API but do not include it at runtime
compileOnly fg.deobf("mezz.jei:jei-${project.jei_version}:api")
compileOnly fg.deobf("mezz.jei:jei-${project.mc_version}:${project.jei_version}:api")
// at runtime, use the full JEI jar
// runtimeOnly fg.deobf("mezz.jei:jei-${project.jei_version}")
runtimeOnly fg.deobf("mezz.jei:jei-${project.mc_version}:${project.jei_version}")
}

// Example for how to get properties into the manifest for reading by the runtime..
Expand All @@ -128,15 +126,18 @@ jar {
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

// we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published
// Note you'll need to add a repository here
def reobfFile = file("$buildDir/reobfJar/output.jar")
def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
builtBy 'reobfJar'
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
artifact reobfArtifact
}
}
repositories {
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=2.0.1
minecraft_version=1.16.1+
minecraft_version=1.15.2

forge_version=1.16.1-32.0.108
forge_mappings=20200707-1.16.1
forge_version=1.15.2-31.1.2
forge_mappings=20200301-1.15.1

# jei
jei_version=1.16.1:7.+
mc_version=1.15.2
jei_version=6.0.0.2

Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.Quaternion;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.IModelTransform;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ItemOverrideList;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.client.renderer.model.ModelBakery;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.util.math.vector.TransformationMatrix;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.BakedItemModel;
import net.minecraftforge.client.model.IModelConfiguration;
import net.minecraftforge.client.model.IModelLoader;
import net.minecraftforge.client.model.ItemLayerModel;
import net.minecraftforge.client.model.ItemMultiLayerBakedModel;
import net.minecraftforge.client.model.ItemTextureQuadConverter;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelTransformComposition;
Expand Down Expand Up @@ -81,14 +81,14 @@ public CeramicBucketModel withFluid(Fluid newFluid)
}

@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation)
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation)
{
RenderMaterial particleLocation = owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : null;
RenderMaterial baseLocation = owner.isTexturePresent("base") ? owner.resolveTexture("base") : null;
Material particleLocation = owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : null;
Material baseLocation = owner.isTexturePresent("base") ? owner.resolveTexture("base") : null;
if (this.isCracked && owner.isTexturePresent("crackedBase")) {
baseLocation = owner.resolveTexture("crackedBase");
}
RenderMaterial fluidMaskLocation = owner.isTexturePresent("fluid") ? owner.resolveTexture("fluid") : null;
Material fluidMaskLocation = owner.isTexturePresent("fluid") ? owner.resolveTexture("fluid") : null;

IModelTransform transformsFromModel = owner.getCombinedTransform();

Expand All @@ -111,12 +111,12 @@ public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<

TransformationMatrix transform = modelTransform.getRotation();

ItemMultiLayerBakedModel.Builder builder = ItemMultiLayerBakedModel.builder(owner, particleSprite, new CeramicBucketModel.ContainedFluidOverrideHandler(overrides, bakery, owner, this), transformMap);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();

if (baseLocation != null)
{
// build base (insidest)
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemLayerModel.getQuadsForSprites(ImmutableList.of(baseLocation), transform, spriteGetter));
builder.addAll(ItemLayerModel.getQuadsForSprites(ImmutableList.of(baseLocation), transform, spriteGetter));
}

if (fluidMaskLocation != null && fluidSprite != null)
Expand All @@ -125,22 +125,20 @@ public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<
if (templateSprite != null)
{
// build liquid layer (inside)
int luminosity = fluid.getAttributes().getLuminosity();
//int luminosity = fluid.getAttributes().getLuminosity();
int color = fluid.getAttributes().getColor();
builder.addQuads(ItemLayerModel.getLayerRenderType(true), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, color, 1, luminosity));
builder.addQuads(ItemLayerModel.getLayerRenderType(true), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1, luminosity));
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, color, 1));
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1));
}
}

builder.setParticle(particleSprite);

return builder.build();
return new BakedModel(bakery, owner, this, builder.build(), particleSprite, Maps.immutableEnumMap(transformMap), Maps.newHashMap(), transform.isIdentity(), modelTransform, owner.isSideLit());
}

@Override
public Collection<RenderMaterial> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
{
Set<RenderMaterial> texs = Sets.newHashSet();
Set<Material> texs = Sets.newHashSet();

if (owner.isTexturePresent("particle")) texs.add(owner.resolveTexture("particle"));
if (owner.isTexturePresent("base")) texs.add(owner.resolveTexture("base"));
Expand Down Expand Up @@ -182,43 +180,62 @@ public CeramicBucketModel read(JsonDeserializationContext deserializationContext

private static final class ContainedFluidOverrideHandler extends ItemOverrideList
{
private final Map<String, IBakedModel> cache = Maps.newHashMap(); // contains all the baked models since they'll never change
private final ItemOverrideList nested;
private final ModelBakery bakery;
private final IModelConfiguration owner;
private final CeramicBucketModel parent;

private ContainedFluidOverrideHandler(ItemOverrideList nested, ModelBakery bakery, IModelConfiguration owner, CeramicBucketModel parent)
private ContainedFluidOverrideHandler(ModelBakery bakery)
{
this.nested = nested;
this.bakery = bakery;
this.owner = owner;
this.parent = parent;
}

@Override
public IBakedModel func_239290_a_(IBakedModel originalModel, ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity)
public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity)
{
IBakedModel overriden = nested.func_239290_a_(originalModel, stack, world, entity);
if (overriden != originalModel) return overriden;
return FluidUtil.getFluidContained(stack)
.map(fluidStack -> {
CeramicBucketModel.BakedModel model = (BakedModel)originalModel;

Fluid fluid = fluidStack.getFluid();
String name = fluid.getRegistryName().toString();

if (!cache.containsKey(name))
if (!model.cache.containsKey(name))
{
CeramicBucketModel unbaked = this.parent.withFluid(fluid);
IBakedModel bakedModel = unbaked.bake(owner, bakery, ModelLoader.defaultTextureGetter(), ModelRotation.X0_Y0, this, new ResourceLocation("forge:bucket_override"));
cache.put(name, bakedModel);
CeramicBucketModel parent = model.parent.withFluid(fluid);
IBakedModel bakedModel = parent.bake(model.owner, bakery, ModelLoader.defaultTextureGetter(), model.originalTransform, model.getOverrides(), new ResourceLocation("forge:bucket_override"));
model.cache.put(name, bakedModel);
return bakedModel;
}

return cache.get(name);
return model.cache.get(name);
})
// not a fluid item apparently
.orElse(originalModel); // empty bucket
}
}

// the dynamic bucket is based on the empty bucket
private static final class BakedModel extends BakedItemModel
{
private final IModelConfiguration owner;
private final CeramicBucketModel parent;
private final Map<String, IBakedModel> cache; // contains all the baked models since they'll never change
private final IModelTransform originalTransform;
private final boolean isSideLit;

BakedModel(ModelBakery bakery,
IModelConfiguration owner, CeramicBucketModel parent,
ImmutableList<BakedQuad> quads,
TextureAtlasSprite particle,
ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms,
Map<String, IBakedModel> cache,
boolean untransformed,
IModelTransform originalTransform, boolean isSideLit)
{
super(quads, particle, transforms, new ContainedFluidOverrideHandler(bakery), untransformed, isSideLit);
this.owner = owner;
this.parent = parent;
this.cache = cache;
this.originalTransform = originalTransform;
this.isSideLit = isSideLit;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.item.BucketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.stats.Stats;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.*;
Expand Down Expand Up @@ -160,8 +159,7 @@ public boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World worl
if (worldIn.isAirBlock(posIn) || flag || flag1 || blockstate.getBlock() instanceof ILiquidContainer && ((ILiquidContainer) blockstate.getBlock()).canContainFluid(worldIn, posIn, blockstate, this.getFluid())) {
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(stack).orElse(null);
FluidStack fluidStack = fluidHandler != null ? fluidHandler.drain(FluidAttributes.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE) : null;
//worldIn.dimension.doesWaterVaporize()
if (fluidStack != null && worldIn.func_230315_m_().func_236040_e_() && this.getFluid(stack).isIn(FluidTags.WATER)) {
if (fluidStack != null && worldIn.dimension.doesWaterVaporize() && this.getFluid(stack).isIn(FluidTags.WATER)) {
fluidAttributes.vaporize(player, worldIn, posIn, fluidStack);
} else if (blockstate.getBlock() instanceof ILiquidContainer && fluid == Fluids.WATER) {
if (((ILiquidContainer) blockstate.getBlock()).receiveFluid(worldIn, posIn, blockstate, ((FlowingFluid) fluid).getStillFluidState(false))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,18 @@ public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @N

for(int j = 0; j < TropicalFishEntity.SPECIAL_VARIANTS.length; ++j) {
if (i == TropicalFishEntity.SPECIAL_VARIANTS[j]) {
//tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212324_b(j))).applyTextStyles(atextformatting));
tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212324_b(j))).func_240701_a_(atextformatting));
tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212324_b(j))).applyTextStyles(atextformatting));
return;
}
}

//tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212327_q(i))).applyTextStyles(atextformatting));
tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212327_q(i))).func_240701_a_(atextformatting));
tooltip.add((new TranslationTextComponent(TropicalFishEntity.func_212327_q(i))).applyTextStyles(atextformatting));
TranslationTextComponent textComponent = new TranslationTextComponent(s);
if (!s.equals(s1)) {
//textComponent.appendText(", ").appendSibling(new TranslationTextComponent(s1));
textComponent.func_240702_b_(", ").func_230529_a_(new TranslationTextComponent(s1));
textComponent.appendText(", ").appendSibling(new TranslationTextComponent(s1));
}

//itextcomponent.applyTextStyles(atextformatting);
textComponent.func_240701_a_(atextformatting);
textComponent.applyTextStyles(atextformatting);
tooltip.add(textComponent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ITextComponent getDisplayName(@Nonnull ItemStack stack) {
ITextComponent fluidText;
if (getFluid(stack) == Fluids.WATER || getFluid(stack) == Fluids.LAVA) {
//vanilla fluids
fluidText = getFluid(stack).getDefaultState().getBlockState().getBlock().getTranslatedName();
fluidText = getFluid(stack).getDefaultState().getBlockState().getBlock().getNameTextComponent();
} else {
//fluids registered by mods
fluidText = new TranslationTextComponent(Util.makeTranslationKey("fluid", ForgeRegistries.FLUIDS.getKey(getFluid(stack))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.ITag;
import net.minecraft.tags.Tag;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;
Expand All @@ -17,7 +17,7 @@

public class CeramicBucketUtils {

private static final ITag.INamedTag<Fluid> MILK_TAG = FluidTags.makeWrapperTag("forge:milk");
private static final Tag<Fluid> MILK_TAG = new FluidTags.Wrapper(new ResourceLocation("forge", "milk"));
private static final List<ResourceLocation> MILK_FLUIDS = new ArrayList<>();
static {
MILK_FLUIDS.add(new ResourceLocation("milk")); //like in FluidUtil.getFilledBucket(...)
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[32,)"
loaderVersion="[31,)"
issueTrackerURL="https://github.com/cech12/CeramicBucket/issues"
license="The MIT License (MIT)"
[[mods]]
Expand All @@ -15,18 +15,18 @@ license="The MIT License (MIT)"
[[dependencies.ceramicbucket]]
modId="forge"
mandatory=true
versionRange="[32.0.108,)"
versionRange="[31.1.2,)"
ordering="NONE"
side="BOTH"
[[dependencies.ceramicbucket]]
modId="minecraft"
mandatory=true
versionRange="[1.16.1,)"
versionRange="[1.15.2,)"
ordering="NONE"
side="BOTH"
[[dependencies.ceramicbucket]]
modId="jei"
mandatory=false
versionRange="[7.0.0.0,)"
versionRange="[6.0.0.2,)"
ordering="NONE"
side="BOTH"

0 comments on commit 4639d43

Please sign in to comment.