MineLittlePony/src/main/java/com/brohoof/minelittlepony/PonyManager.java

143 lines
6 KiB
Java
Raw Normal View History

2015-11-17 06:09:04 +01:00
package com.brohoof.minelittlepony;
2015-08-02 00:36:33 +02:00
import java.util.List;
import java.util.Map;
2015-11-17 06:09:04 +01:00
import com.brohoof.minelittlepony.model.PMAPI;
import com.brohoof.minelittlepony.util.MineLPLogger;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
2015-08-02 00:36:33 +02:00
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.util.ResourceLocation;
public class PonyManager {
2015-12-09 22:05:21 +01:00
private static final String NAMESPACE = "minelittlepony";
public static final ResourceLocation ZOMBIE = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_pony.png");
public static final ResourceLocation ZOMBIE_VILLAGER = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_villager_pony.png");
public static final ResourceLocation PIGMAN = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_pigman_pony.png");
public static final ResourceLocation SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_pony.png");
public static final ResourceLocation WITHER_SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_wither_pony.png");
public static final ResourceLocation STEVE = new ResourceLocation(NAMESPACE, "textures/entity/steve_pony.png");
public static final ResourceLocation ALEX = new ResourceLocation(NAMESPACE, "textures/entity/alex_pony.png");
2015-08-02 00:36:33 +02:00
private static final int MAX_BGPONY_COUNT = 141;
2015-12-09 22:05:21 +01:00
private final List<ResourceLocation> backgroundPonyList = makeBkgndPonies();
private final List<ResourceLocation> villagerList = ImmutableList.<ResourceLocation> builder()
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/farmer_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/librarian_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/priest_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/smith_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/butcher_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/villager_pony.png"))
.build();
private static List<ResourceLocation> makeBkgndPonies() {
ImmutableList.Builder<ResourceLocation> list = ImmutableList.builder();
for (int check = 0; check < MAX_BGPONY_COUNT; ++check) {
2015-12-09 22:05:21 +01:00
list.add(new ResourceLocation(NAMESPACE, "textures/entity/pony/bpony_" + check + ".png"));
}
return list.build();
}
private PonyConfig config;
private Map<ResourceLocation, Pony> ponies = Maps.newHashMap();
private Map<ResourceLocation, Pony> backgroudPonies = Maps.newHashMap();
public PonyManager(PonyConfig config) {
this.config = config;
2015-08-02 00:36:33 +02:00
initmodels();
MineLPLogger.info("Detected %d of %d background ponies installed.", getNumberOfPonies(), MAX_BGPONY_COUNT);
2015-08-02 00:36:33 +02:00
}
public void initmodels() {
MineLPLogger.info("Initializing models...");
PMAPI.init();
MineLPLogger.info("Done initializing models.");
}
private Pony getPonyFromResourceRegistry(ResourceLocation skinResourceLocation, AbstractClientPlayer player) {
Pony myLittlePony;
if (!this.ponies.containsKey(skinResourceLocation)) {
2015-08-02 00:36:33 +02:00
if (player != null) {
myLittlePony = new Pony(player);
} else {
myLittlePony = new Pony(skinResourceLocation);
}
this.ponies.put(skinResourceLocation, myLittlePony);
2015-08-02 00:36:33 +02:00
} else {
myLittlePony = this.ponies.get(skinResourceLocation);
2015-08-02 00:36:33 +02:00
}
return myLittlePony;
}
public Pony getPonyFromResourceRegistry(ResourceLocation skinResourceLocation) {
return this.getPonyFromResourceRegistry(skinResourceLocation, (AbstractClientPlayer) null);
}
public Pony getPonyFromResourceRegistry(AbstractClientPlayer player) {
Pony myLittlePony = this.getPonyFromResourceRegistry(player.getLocationSkin(), player);
if (config.getPonyLevel().get() == PonyLevel.PONIES && myLittlePony.metadata.getRace() == null) {
2015-08-02 00:36:33 +02:00
myLittlePony = this.getPonyFromBackgroundResourceRegistry(player);
}
return myLittlePony;
}
public Pony getPonyFromResourceRegistry(EntityVillager entity) {
int profession = entity.getProfession();
ResourceLocation villagerResourceLocation;
try {
villagerResourceLocation = villagerList.get(profession);
2015-08-02 00:36:33 +02:00
} catch (IndexOutOfBoundsException var5) {
villagerResourceLocation = villagerList.get(5);
2015-08-02 00:36:33 +02:00
}
Pony myLittlePony = this.getPonyFromResourceRegistry(villagerResourceLocation);
// myLittlePony.setVillager(profession);
2015-08-02 00:36:33 +02:00
return myLittlePony;
}
private ResourceLocation getBackgroundPonyResource(AbstractClientPlayer player) {
if (getNumberOfPonies() > 0) {
2015-12-12 05:17:04 +01:00
int backgroundIndex = player.getUniqueID().hashCode() % this.getNumberOfPonies();
2015-08-02 00:36:33 +02:00
if (backgroundIndex < 0) {
backgroundIndex += this.getNumberOfPonies();
}
return backgroundPonyList.get(backgroundIndex);
2015-08-02 00:36:33 +02:00
}
return STEVE;
2015-08-02 00:36:33 +02:00
}
public Pony getPonyFromBackgroundResourceRegistry(AbstractClientPlayer player) {
ResourceLocation textureResourceLocation;
if (player.isUser()) {
textureResourceLocation = (player.getUniqueID().hashCode() & 1) == 0 ? STEVE : ALEX;
2015-08-02 00:36:33 +02:00
} else {
textureResourceLocation = this.getBackgroundPonyResource(player);
2015-08-02 00:36:33 +02:00
}
Pony myLittlePony;
if (!this.backgroudPonies.containsKey(textureResourceLocation)) {
2015-08-02 00:36:33 +02:00
myLittlePony = new Pony(textureResourceLocation);
this.backgroudPonies.put(textureResourceLocation, myLittlePony);
2015-08-02 00:36:33 +02:00
} else {
myLittlePony = this.backgroudPonies.get(textureResourceLocation);
2015-08-02 00:36:33 +02:00
}
return myLittlePony;
}
public int getNumberOfPonies() {
return backgroundPonyList.size();
2015-08-02 00:36:33 +02:00
}
}