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;
|
2015-12-09 04:14:42 +01:00
|
|
|
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 04:14:42 +01:00
|
|
|
|
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-12-09 04:14:42 +01:00
|
|
|
|
2015-08-02 00:36:33 +02:00
|
|
|
private static final int MAX_BGPONY_COUNT = 141;
|
2015-12-09 04:14:42 +01:00
|
|
|
|
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"))
|
2015-12-09 04:14:42 +01:00
|
|
|
.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"));
|
2015-12-09 04:14:42 +01:00
|
|
|
}
|
|
|
|
return list.build();
|
|
|
|
}
|
2015-11-17 06:17:35 +01:00
|
|
|
|
|
|
|
private PonyConfig config;
|
|
|
|
|
2015-12-09 04:14:42 +01:00
|
|
|
private Map<ResourceLocation, Pony> ponies = Maps.newHashMap();
|
|
|
|
private Map<ResourceLocation, Pony> backgroudPonies = Maps.newHashMap();
|
2015-11-17 06:17:35 +01:00
|
|
|
|
|
|
|
public PonyManager(PonyConfig config) {
|
|
|
|
this.config = config;
|
2015-08-02 00:36:33 +02:00
|
|
|
initmodels();
|
2015-12-09 04:14:42 +01:00
|
|
|
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;
|
2015-12-09 04:14:42 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-09 04:14:42 +01:00
|
|
|
this.ponies.put(skinResourceLocation, myLittlePony);
|
2015-08-02 00:36:33 +02:00
|
|
|
} else {
|
2015-12-09 04:14:42 +01:00
|
|
|
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);
|
2015-12-09 04:14:42 +01:00
|
|
|
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 {
|
2015-12-09 04:14:42 +01:00
|
|
|
villagerResourceLocation = villagerList.get(profession);
|
2015-08-02 00:36:33 +02:00
|
|
|
} catch (IndexOutOfBoundsException var5) {
|
2015-12-09 04:14:42 +01:00
|
|
|
villagerResourceLocation = villagerList.get(5);
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pony myLittlePony = this.getPonyFromResourceRegistry(villagerResourceLocation);
|
2015-12-09 04:14:42 +01:00
|
|
|
// myLittlePony.setVillager(profession);
|
2015-08-02 00:36:33 +02:00
|
|
|
return myLittlePony;
|
|
|
|
}
|
|
|
|
|
2015-12-09 04:14:42 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-12-09 04:14:42 +01:00
|
|
|
return backgroundPonyList.get(backgroundIndex);
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
2015-12-09 04:14:42 +01:00
|
|
|
return STEVE;
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Pony getPonyFromBackgroundResourceRegistry(AbstractClientPlayer player) {
|
|
|
|
ResourceLocation textureResourceLocation;
|
2015-12-09 04:14:42 +01:00
|
|
|
if (player.isUser()) {
|
|
|
|
textureResourceLocation = (player.getUniqueID().hashCode() & 1) == 0 ? STEVE : ALEX;
|
2015-08-02 00:36:33 +02:00
|
|
|
} else {
|
2015-12-09 04:14:42 +01:00
|
|
|
textureResourceLocation = this.getBackgroundPonyResource(player);
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pony myLittlePony;
|
2015-12-09 04:14:42 +01:00
|
|
|
if (!this.backgroudPonies.containsKey(textureResourceLocation)) {
|
2015-08-02 00:36:33 +02:00
|
|
|
myLittlePony = new Pony(textureResourceLocation);
|
2015-12-09 04:14:42 +01:00
|
|
|
this.backgroudPonies.put(textureResourceLocation, myLittlePony);
|
2015-08-02 00:36:33 +02:00
|
|
|
} else {
|
2015-12-09 04:14:42 +01:00
|
|
|
myLittlePony = this.backgroudPonies.get(textureResourceLocation);
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return myLittlePony;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNumberOfPonies() {
|
2015-12-09 04:14:42 +01:00
|
|
|
return backgroundPonyList.size();
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
}
|