Skip to content

Commit

Permalink
Fixed z-fighting for wolves and camels (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
lclc98 authored and GirafiStudios committed May 17, 2019
1 parent a039447 commit 55d887a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 172 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.google.common.collect.Maps;
import com.teammetallurgy.atum.client.model.entity.ModelCamel;
import com.teammetallurgy.atum.client.render.entity.layer.LayerCamelArmor;
import com.teammetallurgy.atum.client.render.entity.layer.LayerCamelCarpet;
import com.teammetallurgy.atum.entity.animal.EntityCamel;
import com.teammetallurgy.atum.utils.Constants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.LayeredTexture;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -23,26 +25,40 @@ public class RenderCamel extends RenderLiving<EntityCamel> {

public RenderCamel(RenderManager renderManager) {
super(renderManager, new ModelCamel(0.0F), 0.7F);
this.addLayer(new LayerCamelArmor(this));
this.addLayer(new LayerCamelCarpet(this));
}

@Override
@Nullable
protected ResourceLocation getEntityTexture(@Nonnull EntityCamel camel) {
String texture = camel.getTexture();
ResourceLocation location = CACHE.get(texture);
String textureName = camel.getTexture();

if (camel.hasCustomName()) {
String name = camel.getCustomNameTag();
if (name.equalsIgnoreCase("girafi")) {
return GIRAFI;
}
}
ResourceLocation location = CACHE.get(textureName);
if (location == null) {
location = new ResourceLocation(texture);
CACHE.put(texture, location);
location = new ResourceLocation(textureName);
String[] texturePath = new String[3];
if (camel.hasCustomName()) {
String name = camel.getCustomNameTag();
if (name.equalsIgnoreCase("girafi")) {
texturePath[0] = GIRAFI.toString();
}
} else {
texturePath[0] = new ResourceLocation(Constants.MOD_ID, "textures/entity/camel_" + camel.getVariant()) + ".png";
}

ItemStack armor = camel.getArmor();
if (!armor.isEmpty()) {
EntityCamel.ArmorType armorType = EntityCamel.ArmorType.getByItemStack(armor);
texturePath[1] = armorType.getTextureName();
}

EnumDyeColor color = camel.getColor();
if (color != null) {
texturePath[2] = new ResourceLocation(Constants.MOD_ID, "textures/entity/camel_carpet/camel_carpet_" + color.getDyeColorName()) + ".png";
}
Minecraft.getMinecraft().getTextureManager().loadTexture(location, new LayeredTexture(texturePath));
CACHE.put(textureName, location);
}

return location;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.Maps;
import com.teammetallurgy.atum.client.render.entity.layer.LayerDesertWolfCollar;
import com.teammetallurgy.atum.client.render.entity.layer.LayerWolfSaddle;
import com.teammetallurgy.atum.entity.animal.EntityDesertWolf;
import com.teammetallurgy.atum.utils.Constants;
import net.minecraft.client.Minecraft;
Expand All @@ -24,10 +23,10 @@ public class RenderDesertWolf extends RenderLiving<EntityDesertWolf> {
private static final Map<String, ResourceLocation> CACHE = Maps.newHashMap();
private static final ResourceLocation TAMED_DESERT_WOLF_TEXTURES = new ResourceLocation(Constants.MOD_ID, "textures/entity/desert_wolf_tame.png");
private static final ResourceLocation ANGRY_DESERT_WOLF_TEXTURES = new ResourceLocation(Constants.MOD_ID, "textures/entity/desert_wolf_angry.png");
private static final ResourceLocation SADDLE_DESERT_WOLF_TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/entity/desert_wolf_saddle.png");

public RenderDesertWolf(RenderManager renderManager, ModelBase modelBase, float shadowSize) {
super(renderManager, modelBase, shadowSize);
this.addLayer(new LayerWolfSaddle(this));
this.addLayer(new LayerDesertWolfCollar(this));
}

Expand All @@ -49,27 +48,27 @@ public void doRender(@Nonnull EntityDesertWolf desertWolf, double x, double y, d

@Override
protected ResourceLocation getEntityTexture(@Nonnull EntityDesertWolf desertWolf) {
ItemStack wolfArmor = desertWolf.getArmor();
if (desertWolf.isTamed()) {
if (desertWolf.isArmor(wolfArmor)) {
EntityDesertWolf.ArmorType armorType = EntityDesertWolf.ArmorType.getByItemStack(wolfArmor);
ResourceLocation armorTexture = CACHE.get(armorType.getTextureName());
if (armorTexture == null) {
armorTexture = new ResourceLocation(armorType.getTextureName());
Minecraft.getMinecraft().getTextureManager().loadTexture(armorTexture, new LayeredTexture(armorType.getTextureName()));
CACHE.put(armorType.getTextureName(), armorTexture);
}
return armorTexture;
String textureName = desertWolf.getTexture();

ResourceLocation location = CACHE.get(textureName);
if (location == null) {
location = new ResourceLocation(textureName);
String[] texturePath = new String[3];
texturePath[0] = desertWolf.isAngry() ? ANGRY_DESERT_WOLF_TEXTURES.toString() : TAMED_DESERT_WOLF_TEXTURES.toString();

ItemStack armor = desertWolf.getArmor();
if (!armor.isEmpty()) {
EntityDesertWolf.ArmorType armorType = EntityDesertWolf.ArmorType.getByItemStack(armor);
texturePath[1] = armorType.getTextureName();
}
ResourceLocation texture = CACHE.get(TAMED_DESERT_WOLF_TEXTURES.toString());
if (texture == null) {
Minecraft.getMinecraft().getTextureManager().loadTexture(TAMED_DESERT_WOLF_TEXTURES, new LayeredTexture(TAMED_DESERT_WOLF_TEXTURES.toString()));
CACHE.put(TAMED_DESERT_WOLF_TEXTURES.toString(), TAMED_DESERT_WOLF_TEXTURES);

if (desertWolf.isSaddled()){
texturePath[2] = SADDLE_DESERT_WOLF_TEXTURE.toString();
}
return texture;
} else {
return ANGRY_DESERT_WOLF_TEXTURES;
Minecraft.getMinecraft().getTextureManager().loadTexture(location, new LayeredTexture(texturePath));
CACHE.put(textureName, location);
}
return location;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
Expand All @@ -50,7 +49,6 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.UUID;

public class EntityCamel extends AbstractHorse implements IRangedAttackMob {
Expand All @@ -61,7 +59,7 @@ public class EntityCamel extends AbstractHorse implements IRangedAttackMob {
private static final DataParameter<ItemStack> ARMOR_STACK = EntityDataManager.createKey(EntityCamel.class, DataSerializers.ITEM_STACK);
private static final UUID ARMOR_MODIFIER_UUID = UUID.fromString("13a48eeb-c17d-45cc-8163-e7210a6adfc9");
public static final float CAMEL_RIDING_SPEED_AMOUNT = 0.65F;
private String texturePath;
private String textureName;
private boolean didSpit;
private EntityCamel caravanHead;
private EntityCamel caravanTail;
Expand All @@ -79,9 +77,7 @@ public EntityCamel(World world) {
protected void entityInit() {
super.entityInit();
this.dataManager.register(DATA_COLOR_ID, -1);
if (this.hasSkinVariants()) {
this.dataManager.register(VARIANT, 0);
}
this.dataManager.register(VARIANT, 0);
this.dataManager.register(LEFT_CRATE, ItemStack.EMPTY);
this.dataManager.register(RIGHT_CRATE, ItemStack.EMPTY);
this.dataManager.register(ARMOR_STACK, ItemStack.EMPTY);
Expand All @@ -100,10 +96,8 @@ protected void applyEntityAttributes() {
public IEntityLivingData onInitialSpawn(@Nonnull DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
livingdata = super.onInitialSpawn(difficulty, livingdata);

if (hasSkinVariants()) {
final int variant = this.getCamelVariantBiome();
this.setVariant(variant);
}
final int variant = this.getCamelVariantBiome();
this.setVariant(variant);
return livingdata;
}

Expand Down Expand Up @@ -184,20 +178,16 @@ public void onUpdate() {

if (this.world.isRemote && this.dataManager.isDirty()) {
this.dataManager.setClean();
this.texturePath = null;
this.textureName = null;
}
}

private boolean hasSkinVariants() {
return true;
}

private void setVariant(int variant) {
this.dataManager.set(VARIANT, variant);
this.texturePath = null;
this.textureName = null;
}

private int getVariant() {
public int getVariant() {
return this.dataManager.get(VARIANT);
}

Expand All @@ -224,14 +214,28 @@ private int getCamelVariantBiome() {

@SideOnly(Side.CLIENT)
public String getTexture() {
if (this.texturePath == null) {
if (this.hasSkinVariants()) {
this.texturePath = new ResourceLocation(Constants.MOD_ID, "textures/entity/camel_" + this.getVariant()) + ".png";
if (this.textureName == null) {
if (this.hasCustomName()) {
String name = this.getCustomNameTag();
if (name.equalsIgnoreCase("girafi")) {
this.textureName = "girafi";
}
} else {
this.texturePath = new ResourceLocation(Constants.MOD_ID, "textures/entity/camel") + ".png";
this.textureName = String.valueOf(this.getVariant());
}

ItemStack armor = this.getArmor();
if (!armor.isEmpty()) {
EntityCamel.ArmorType armorType = EntityCamel.ArmorType.getByItemStack(armor);
this.textureName += "_" + armorType.getName();
}

EnumDyeColor color = this.getColor();
if (color != null) {
this.textureName += "_" + color.getDyeColorName();
}
}
return this.texturePath;
return this.textureName;
}

@Override
Expand Down Expand Up @@ -767,7 +771,7 @@ public enum ArmorType {
GOLD(7, "gold"),
DIAMOND(11, "diamond");

private final ResourceLocation textureName;
private final String textureName;
private final String typeName;
private final int protection;

Expand All @@ -780,7 +784,7 @@ public enum ArmorType {
ArmorType(int armorStrength, String typeName) {
this.protection = armorStrength;
this.typeName = typeName;
this.textureName = new ResourceLocation(Constants.MOD_ID, "textures/entity/armor/camel_armor_" + typeName + ".png");
this.textureName = new ResourceLocation(Constants.MOD_ID, "textures/entity/armor/camel_armor_" + typeName) + ".png";
}

public int getProtection() {
Expand All @@ -791,7 +795,7 @@ public String getName() {
return typeName;
}

public ResourceLocation getTextureName() {
public String getTextureName() {
return textureName;
}

Expand Down

0 comments on commit 55d887a

Please sign in to comment.