Use an interface for Pony instead of the class

This commit is contained in:
Sollace 2018-08-30 16:12:21 +02:00
parent 0debe17afe
commit c2ac9cbbfa
16 changed files with 107 additions and 37 deletions

View file

@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel;
import com.voxelmodpack.hdskins.ISkinCacheClearListener;
@ -43,7 +44,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
private PonyConfig config;
private Map<ResourceLocation, Pony> poniesCache = Maps.newHashMap();
private Map<ResourceLocation, IPony> poniesCache = Maps.newHashMap();
public PonyManager(PonyConfig config) {
this.config = config;
@ -54,7 +55,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
*
* @param resource A texture resource
*/
public Pony getPony(ResourceLocation resource) {
public IPony getPony(ResourceLocation resource) {
return poniesCache.computeIfAbsent(resource, Pony::new);
}
@ -64,7 +65,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
*
* @param player the player
*/
public Pony getPony(AbstractClientPlayer player) {
public IPony getPony(AbstractClientPlayer player) {
ResourceLocation skin = player.getLocationSkin();
UUID uuid = player.getGameProfile().getId();
@ -75,7 +76,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
return getPony(skin, uuid);
}
public Pony getPony(NetworkPlayerInfo playerInfo) {
public IPony getPony(NetworkPlayerInfo playerInfo) {
ResourceLocation skin = playerInfo.getLocationSkin();
UUID uuid = playerInfo.getGameProfile().getId();
@ -97,8 +98,8 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
* @param resource A texture resource
* @param uuid id of a player or entity
*/
public Pony getPony(ResourceLocation resource, UUID uuid) {
Pony pony = getPony(resource);
public IPony getPony(ResourceLocation resource, UUID uuid) {
IPony pony = getPony(resource);
if (config.getPonyLevel() == PonyLevel.PONIES && pony.getMetadata().getRace().isHuman()) {
return getBackgroundPony(uuid);
@ -112,7 +113,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
*
* @param uuid id of a player or entity
*/
public Pony getDefaultPony(UUID uuid) {
public IPony getDefaultPony(UUID uuid) {
if (config.getPonyLevel() != PonyLevel.PONIES) {
return getPony(DefaultPlayerSkin.getDefaultSkin(uuid));
}
@ -120,7 +121,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
return getBackgroundPony(uuid);
}
private Pony getBackgroundPony(UUID uuid) {
private IPony getBackgroundPony(UUID uuid) {
if (getNumberOfPonies() == 0 || isUser(uuid)) {
return getPony(getDefaultSkin(uuid));
}
@ -138,7 +139,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl
/**
* De-registers a pony from the cache.
*/
public Pony removePony(ResourceLocation resource) {
public IPony removePony(ResourceLocation resource) {
return poniesCache.remove(resource);
}

View file

@ -1,7 +1,7 @@
package com.minelittlepony.ducks;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import net.minecraft.entity.EntityLivingBase;
@ -15,5 +15,5 @@ public interface IRenderPony<T extends EntityLivingBase> {
*/
ModelWrapper getModelWrapper();
Pony getEntityPony(T entity);
IPony getEntityPony(T entity);
}

View file

@ -4,6 +4,7 @@ import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.model.player.PlayerModels;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyRace;
import com.minelittlepony.render.layer.LayerPonyElytra;
@ -41,7 +42,7 @@ public class RenderPonyModel extends RenderPlayerModel<EntityPonyModel> implemen
}
@Override
public Pony getEntityPony(EntityPonyModel entity) {
public IPony getEntityPony(EntityPonyModel entity) {
return MineLittlePony.getInstance().getManager().getPony(getEntityTexture(entity));
}
@ -67,7 +68,7 @@ public class RenderPonyModel extends RenderPlayerModel<EntityPonyModel> implemen
boolean slim = playermodel.usesThinSkin();
Pony thePony = MineLittlePony.getInstance().getManager().getPony(loc);
IPony thePony = MineLittlePony.getInstance().getManager().getPony(loc);
PonyRace race = thePony.getRace(false);

View file

@ -6,8 +6,8 @@ import com.minelittlepony.model.capabilities.IModel;
import com.minelittlepony.model.capabilities.IModelPart;
import com.minelittlepony.model.components.PonySnout;
import com.minelittlepony.model.components.PonyTail;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.pony.data.IPonyData;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyData;
import com.minelittlepony.pony.data.PonySize;
import com.minelittlepony.render.AbstractPonyRenderer;
@ -76,7 +76,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P
rainboom &= Math.sqrt(entity.motionX * entity.motionX + entity.motionZ * entity.motionZ) > 0.4F;
}
public void updateLivingState(EntityLivingBase entity, Pony pony) {
public void updateLivingState(EntityLivingBase entity, IPony pony) {
isChild = entity.isChild();
isSneak = entity.isSneaking();
isSleeping = entity.isPlayerSleeping();

View file

@ -2,7 +2,7 @@ package com.minelittlepony.model.ponies;
import com.minelittlepony.model.components.SeaponyTail;
import com.minelittlepony.model.player.ModelUnicorn;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.PonyRenderer;
import com.minelittlepony.render.plane.PlaneRenderer;
@ -25,7 +25,7 @@ public class ModelSeapony extends ModelUnicorn {
}
@Override
public void updateLivingState(EntityLivingBase entity, Pony pony) {
public void updateLivingState(EntityLivingBase entity, IPony pony) {
super.updateLivingState(entity, pony);
// Seaponies can't sneak, silly

View file

@ -12,7 +12,7 @@ import net.minecraft.util.math.MathHelper;
import org.lwjgl.opengl.GL11;
import com.minelittlepony.model.player.ModelZebra;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.PonyRenderer;
public class ModelWitchPony extends ModelZebra {
@ -26,7 +26,7 @@ public class ModelWitchPony extends ModelZebra {
}
@Override
public void updateLivingState(EntityLivingBase entity, Pony pony) {
public void updateLivingState(EntityLivingBase entity, IPony pony) {
super.updateLivingState(entity, pony);
EntityWitch witch = ((EntityWitch) entity);

View file

@ -0,0 +1,62 @@
package com.minelittlepony.pony.data;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import com.minelittlepony.MineLittlePony;
public interface IPony {
/**
* Gets or creates a new pony associated with the provided player.
* The results of this method should not be cached.
*/
static IPony forPlayer(AbstractClientPlayer player) {
return MineLittlePony.getInstance().getManager().getPony(player);
}
/**
* Returns true if the provided entity is flying like a pegasus.
* True if the entity is off the ground, has race with wings.
* Creative flight counts only if the entity is <i>not</i> on the ground.
*
* Entities that are riding, climbing a ladder, or swimming are <i>not</i> flying.
*/
boolean isPegasusFlying(EntityLivingBase entity);
/**
* Returns true if the provided antity is actively wimming.
* That is, it should be fully submerged (isFullySubmerged returns true)
* and is not standing on the (river) bed or riding a ladder or any other entity.
*/
boolean isSwimming(EntityLivingBase entity);
/**
* Returns true if the provided entity is fully submerged with water reaching the entity's eyeheight or above.
*/
boolean isFullySubmerged(EntityLivingBase entity);
/**
* Returns true if an entity is wearing any headgear. This is used to hide things like the snout when wearing items
* such as the jack-o-lantern, helmet, or player's head.
*/
boolean isWearingHeadgear(EntityLivingBase entity);
/**
* Gets the race associated with this pony.
*
* @param ignorePony True to ignore the client's current pony level setting.
*/
PonyRace getRace(boolean ignorePony);
/**
* Gets the texture used for rendering this pony.
* @return
*/
ResourceLocation getTexture();
/**
* Gets the metadata associated with this pony's model texture.
*/
IPonyData getMetadata();
}

View file

@ -27,7 +27,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
public class Pony {
public class Pony implements IPony {
private static final AtomicInteger ponyCount = new AtomicInteger();
@ -94,15 +94,18 @@ public class Pony {
return PonyData.parse(bufferedimage);
}
@Override
public boolean isPegasusFlying(EntityLivingBase entity) {
return getRace(false).hasWings() &&
!(entity.onGround || entity.isRiding() || entity.isOnLadder() || entity.isInWater());
}
@Override
public boolean isSwimming(EntityLivingBase entity) {
return isFullySubmerged(entity) && !(entity.onGround || entity.isOnLadder());
}
@Override
public boolean isFullySubmerged(EntityLivingBase entity) {
return entity.isInWater()
&& entity.getEntityWorld().getBlockState(new BlockPos(getVisualEyePosition(entity))).getMaterial() == Material.WATER;
@ -114,6 +117,7 @@ public class Pony {
return new Vec3d(entity.posX, entity.posY + (double) entity.getEyeHeight() * size.getScaleFactor(), entity.posZ);
}
@Override
public boolean isWearingHeadgear(EntityLivingBase entity) {
ItemStack stack = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
@ -126,14 +130,17 @@ public class Pony {
return !(item instanceof ItemArmor) || ((ItemArmor) item).getEquipmentSlot() != EntityEquipmentSlot.HEAD;
}
@Override
public PonyRace getRace(boolean ignorePony) {
return metadata.getRace().getEffectiveRace(ignorePony);
}
@Override
public ResourceLocation getTexture() {
return texture;
}
@Override
public IPonyData getMetadata() {
return metadata;
}

View file

@ -1,7 +1,6 @@
package com.minelittlepony.pony.data;
import com.google.common.base.MoreObjects;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.model.anim.BasicEasingInterpolator;
import com.minelittlepony.model.anim.IInterpolator;

View file

@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL14;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.util.coordinates.Color;
import com.mumfrey.liteloader.client.overlays.IMinecraft;
@ -70,7 +70,7 @@ public class LevitatingItemRenderer {
* Renders an item in first person optionally with a magical overlay.
*/
public void renderItemInFirstPerson(ItemRenderer renderer, AbstractClientPlayer entity, ItemStack stack, TransformType transform, boolean left) {
Pony pony = MineLittlePony.getInstance().getManager().getPony(entity);
IPony pony = MineLittlePony.getInstance().getManager().getPony(entity);
pushMatrix();

View file

@ -1,7 +1,7 @@
package com.minelittlepony.render;
import com.minelittlepony.model.components.ModelPonyHead;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.PonySkullRenderer.ISkull;
public abstract class PonySkull implements ISkull {
@ -14,7 +14,7 @@ public abstract class PonySkull implements ISkull {
}
@Override
public void bindPony(Pony pony) {
public void bindPony(IPony pony) {
ponyHead.metadata = pony.getMetadata();
}

View file

@ -3,7 +3,7 @@ package com.minelittlepony.render;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.skull.PlayerSkullRenderer;
import com.minelittlepony.render.skull.SkeletonSkullRenderer;
import com.minelittlepony.render.skull.WitherSkullRenderer;
@ -175,6 +175,6 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende
ResourceLocation getSkinResource(@Nullable GameProfile profile);
void bindPony(Pony pony);
void bindPony(IPony pony);
}
}

View file

@ -3,7 +3,7 @@ package com.minelittlepony.render;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.transform.PonyPosture;
import net.minecraft.client.renderer.GlStateManager;
@ -15,7 +15,7 @@ public class RenderPony<T extends EntityLivingBase> {
protected AbstractPonyModel ponyModel;
private Pony pony;
private IPony pony;
private IRenderPony<T> renderer;
@ -84,7 +84,7 @@ public class RenderPony<T extends EntityLivingBase> {
playerModel.apply(pony.getMetadata());
}
public Pony getPony(T entity) {
public IPony getPony(T entity) {
updateModel(entity);
return pony;
}

View file

@ -3,7 +3,7 @@ package com.minelittlepony.render;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.layer.LayerHeldPonyItem;
import com.minelittlepony.render.layer.LayerHeldPonyItemMagical;
import com.minelittlepony.render.layer.LayerPonyArmor;
@ -75,7 +75,7 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
}
@Override
public Pony getEntityPony(T entity) {
public IPony getEntityPony(T entity) {
return MineLittlePony.getInstance().getManager().getPony(getEntityTexture(entity));
}

View file

@ -3,7 +3,7 @@ package com.minelittlepony.render.player;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.render.RenderPony;
import com.minelittlepony.render.layer.LayerDJPon3Head;
import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder;
@ -127,7 +127,7 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony<Abstra
}
@Override
public Pony getEntityPony(AbstractClientPlayer player) {
public IPony getEntityPony(AbstractClientPlayer player) {
return MineLittlePony.getInstance().getManager().getPony(player);
}

View file

@ -1,7 +1,7 @@
package com.minelittlepony.render.player;
import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.IPony;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.entity.RenderManager;
@ -19,8 +19,8 @@ public class RenderSeaponyPlayer extends RenderPonyPlayer {
}
@Override
public Pony getEntityPony(AbstractClientPlayer player) {
Pony pony = super.getEntityPony(player);
public IPony getEntityPony(AbstractClientPlayer player) {
IPony pony = super.getEntityPony(player);
boolean wet = pony.isFullySubmerged(player);