This commit is contained in:
KAMKEEL committed 2023-03-20 11:16:33 -04:00
commit 4302ac4a2b
14 files changed
+434 -234

No files matched your search

+3 -7
View File
@@ -78,13 +78,9 @@ public class NPCSpawning {
x += world.rand.nextInt(b1) - world.rand.nextInt(b1);
z += world.rand.nextInt(b1) - world.rand.nextInt(b1);
Block block = world.getBlock(x, y, z);
String name = world.getBiomeGenForCoords(x, z).biomeName;
SpawnData data = SpawnController.instance.getRandomSpawnData(name, block.getMaterial() == Material.air);
SpawnData data = SpawnController.instance.getRandomSpawnData(name, world.provider.dimensionId);
if (data == null || !canCreatureTypeSpawnAtLocation(data, world, x, y, z) || world.getClosestPlayer(x, y, z, 24.0D) != null)
continue;
@@ -115,7 +111,7 @@ public class NPCSpawning {
public static void performWorldGenSpawning(World world, int x, int z, Random rand){
BiomeGenBase biome = world.getBiomeGenForCoords(x + 8, z + 8);
while (rand.nextFloat() < biome.getSpawningChance()){
SpawnData data = SpawnController.instance.getRandomSpawnData(biome.biomeName, true);
SpawnData data = SpawnController.instance.getRandomSpawnData(biome.biomeName, world.provider.dimensionId);
if(data == null)
continue;
@@ -153,7 +149,7 @@ public class NPCSpawning {
EntityLiving entityliving;
try{
NBTTagCompound[] allCompoundList = new NBTTagCompound[]{data.compound1,data.compound2,data.compound3,data.compound4,data.compound5};
NBTTagCompound[] allCompoundList = data.spawnCompounds.values().toArray(new NBTTagCompound[0]);
ArrayList<Entity> entities = new ArrayList<>();
for (NBTTagCompound compound : allCompoundList) {
Entity entity;
@@ -88,6 +88,13 @@ public class PacketHandlerServer{
} else if (type == EnumPacketServer.QuestLogToServer) {
updateQuestLogData(buffer, player);
return;
} else if(type == EnumPacketServer.DimensionsGet){
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int id : DimensionManager.getStaticDimensionIDs()){
WorldProvider provider = DimensionManager.createProviderFor(id);
map.put(provider.getDimensionName(), id);
}
NoppesUtilServer.sendScrollData(player, map);
}
if(type.needsNpc && npc == null){
@@ -330,15 +337,7 @@ public class PacketHandlerServer{
}
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.DimensionsGet){
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int id : DimensionManager.getStaticDimensionIDs()){
WorldProvider provider = DimensionManager.createProviderFor(id);
map.put(provider.getDimensionName(), id);
}
NoppesUtilServer.sendScrollData(player, map);
}
else if(type == EnumPacketServer.DimensionTeleport){
if(type == EnumPacketServer.DimensionTeleport){
int dimension = buffer.readInt();
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
ChunkCoordinates coords = world.getEntrancePortalLocation();
@@ -8,6 +8,7 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.customitem.ImageData;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.SkinOverlay;
@@ -20,6 +21,7 @@ public class Client {
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
private static HashMap<String, ImageData> imageDataCache = new HashMap<>();
public static void sendData(EnumPacketServer enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -31,4 +33,12 @@ public class Client {
e.printStackTrace();
}
}
public static ImageData getImageData(String directory) {
if (!imageDataCache.containsKey(directory)) {
ImageData downloadData = new ImageData(directory);
imageDataCache.put(directory, downloadData);
}
return imageDataCache.get(directory);
}
}
@@ -53,6 +53,7 @@ import noppes.npcs.client.gui.script.GuiScriptItem;
import noppes.npcs.client.model.*;
import noppes.npcs.client.renderer.*;
import noppes.npcs.client.renderer.blocks.*;
import noppes.npcs.client.renderer.customitem.CustomItemRenderer;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.ConfigScript;
@@ -111,7 +111,9 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
if(sel == null)
return null;
return ClientCloneController.Instance.getCloneData(player, sel, activeTab);
NBTTagCompound compound = ClientCloneController.Instance.getCloneData(player, sel, activeTab);
compound.setString("ClonedName", sel);
return compound;
}
public void buttonEvent(GuiButton guibutton)
@@ -0,0 +1,119 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.SpawnData;
import java.util.*;
public class SubGuiNpcDimensions extends SubGuiInterface implements IScrollData
{
private final SpawnData data;
private GuiCustomScroll allDimensions;
private HashMap<String, Integer> dimensionMap = new HashMap<>();
private GuiCustomScroll dataDimensions;
public SubGuiNpcDimensions(SpawnData data){
this.data = data;
setBackground("menubg.png");
xSize = 346;
ySize = 216;
closeOnEsc = true;
Client.sendData(EnumPacketServer.DimensionsGet);
}
public void initGui(){
super.initGui();
if(allDimensions == null){
allDimensions = new GuiCustomScroll(this,0);
allDimensions.setSize(140, 180);
}
allDimensions.guiLeft = guiLeft + 4;
allDimensions.guiTop = guiTop + 14;
this.addScroll(allDimensions);
addLabel(new GuiNpcLabel(1, "spawning.availableDimensions", guiLeft + 4, guiTop + 4));
if(dataDimensions == null){
dataDimensions = new GuiCustomScroll(this,1);
dataDimensions.setSize(140, 180);
}
dataDimensions.guiLeft = guiLeft + 200;
dataDimensions.guiTop = guiTop + 14;
this.addScroll(dataDimensions);
addLabel(new GuiNpcLabel(2, "spawning.spawningDimensions", guiLeft + 200, guiTop + 4));
ArrayList<String> dimensions = new ArrayList<>();
Set<Map.Entry<String,Integer>> entrySet = this.dimensionMap.entrySet();
for (Map.Entry<String,Integer> entry : entrySet) {
if (this.data.dimensions.contains(entry.getValue())) {
dimensions.add(entry.getKey());
}
}
dataDimensions.setList(dimensions);
addButton(new GuiNpcButton(1, guiLeft + 145, guiTop + 40, 55, 20, ">"));
addButton(new GuiNpcButton(2, guiLeft + 145, guiTop + 62, 55, 20, "<"));
addButton(new GuiNpcButton(3, guiLeft + 145, guiTop + 90, 55, 20, ">>"));
addButton(new GuiNpcButton(4, guiLeft + 145, guiTop + 112, 55, 20, "<<"));
addButton(new GuiNpcButton(66, guiLeft + 260, guiTop + 194, 60, 20, "gui.done"));
}
protected void actionPerformed(GuiButton guibutton){
GuiNpcButton button = (GuiNpcButton) guibutton;
if(button.id == 1){
if(allDimensions.hasSelected()){
data.dimensions.add(dimensionMap.get(allDimensions.getSelected()));
allDimensions.selected = -1;
initGui();
}
}
if(button.id == 2){
if(dataDimensions.hasSelected()){
data.dimensions.remove(dimensionMap.get(dataDimensions.getSelected()));
dataDimensions.selected = -1;
initGui();
}
}
if(button.id == 3){
data.dimensions.clear();
this.data.dimensions.addAll(this.dimensionMap.values());
allDimensions.selected = -1;
initGui();
}
if(button.id == 4){
data.dimensions.clear();
allDimensions.selected = -1;
initGui();
}
if(button.id == 66){
close();
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
this.allDimensions.setList(list);
this.dimensionMap = data;
ArrayList<String> dimensions = new ArrayList<>();
Set<Map.Entry<String,Integer>> entrySet = this.dimensionMap.entrySet();
for (Map.Entry<String,Integer> entry : entrySet) {
if (this.data.dimensions.contains(entry.getValue())) {
dimensions.add(entry.getKey());
}
}
dataDimensions.setList(dimensions);
initGui();
}
@Override
public void setSelected(String selected) {
}
}
@@ -6,22 +6,22 @@ import net.minecraft.util.StatCollector;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.GuiNpcMobSpawnerSelector;
import noppes.npcs.client.gui.SubGuiNpcBiomes;
import noppes.npcs.client.gui.SubGuiNpcDimensions;
import noppes.npcs.client.gui.SubGuiSpawningOptions;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.DialogImage;
import noppes.npcs.controllers.data.SpawnData;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.HashMap;
import java.util.Vector;
import java.util.*;
public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, IScrollData, ITextfieldListener, ICustomScrollListener, ISliderListener{
private GuiCustomScroll scroll;
private GuiCustomScroll scrollNaturalSpawns;
private GuiCustomScroll spawnEntryScroll;
private HashMap<String, Integer> data = new HashMap<String, Integer>();
private SpawnData spawn = new SpawnData();
private int slotSelected;
public GuiNpcNaturalSpawns(EntityNPCInterface npc) {
super(npc);
@@ -31,59 +31,62 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
@Override
public void initGui(){
super.initGui();
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll.setSize(143, 208);
if(this.scrollNaturalSpawns == null){
this.scrollNaturalSpawns = new GuiCustomScroll(this,0);
this.scrollNaturalSpawns.setSize(143, 208);
}
scroll.guiLeft = guiLeft + 214;
scroll.guiTop = guiTop + 4;
this.addScroll(scroll);
this.scrollNaturalSpawns.guiLeft = guiLeft + 214;
this.scrollNaturalSpawns.guiTop = guiTop + 4;
this.addScroll(this.scrollNaturalSpawns);
this.addButton(new GuiNpcButton(1,guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
if(spawn.id >= 0)
if(this.spawn.id >= 0)
showSpawn();
}
private void showSpawn() {
addLabel(new GuiNpcLabel(1,"gui.title", guiLeft + 4, guiTop + 8));
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 60, guiTop + 3, 140, 20, spawn.name));
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 60, guiTop + 3, 140, 20, this.spawn.name));
int y = guiTop + 30;
addLabel(new GuiNpcLabel(3,"spawning.biomes", guiLeft + 4, y));
addButton(new GuiNpcButton(3, guiLeft + 120, y - 5, 50, 20, "selectServer.edit"));
addButton(new GuiNpcButton(3, guiLeft + 40, y - 5, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(11,StatCollector.translateToLocal("Dimensions"), guiLeft + 95, y));
addButton(new GuiNpcButton(11, guiLeft + 150, y - 5, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(4,"spawning.options", guiLeft + 4, y += 22));
addButton(new GuiNpcButton(4, guiLeft + 120, y - 5, 50, 20, "selectServer.edit"));
addButton(new GuiNpcButton(4, guiLeft + 90, y - 5, 50, 20, "selectServer.edit"));
addSlider(new GuiNpcSlider(this, 5, guiLeft + 4, y += 17, 180, 20, (float)spawn.itemWeight / 100));
addSlider(new GuiNpcSlider(this, 5, guiLeft + 4, y += 17, 180, 20, (float)this.spawn.itemWeight / 100));
this.addButton(new GuiNpcButton(25, guiLeft + 14, y += 23,20,20, "X"));
addLabel(new GuiNpcLabel(6, "1:", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(6, guiLeft + 36, y, 170, 20, getTitle(spawn.compound1)));
if (this.spawnEntryScroll == null) {
this.spawnEntryScroll = new GuiCustomScroll(this, 20, false);
}
this.spawnEntryScroll.guiLeft = guiLeft + 4;
this.spawnEntryScroll.guiTop = y + 40;
this.spawnEntryScroll.setSize(50, 102);
ArrayList<String> list = new ArrayList<>();
Set<Integer> keySet = this.spawn.spawnCompounds.keySet();
for (int i : keySet) {
list.add(String.valueOf(i));
}
this.spawnEntryScroll.setList(list);
addScroll(this.spawnEntryScroll);
this.addButton(new GuiNpcButton(26, guiLeft + 14, y += 22,20,20, "X"));
addLabel(new GuiNpcLabel(7, "2:", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(7, guiLeft + 36, y, 170, 20, getTitle(spawn.compound2)));
this.addButton(new GuiNpcButton(27, guiLeft + 14, y += 22,20,20, "X"));
addLabel(new GuiNpcLabel(8, "3:", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(8, guiLeft + 36, y, 170, 20, getTitle(spawn.compound3)));
this.addButton(new GuiNpcButton(28, guiLeft + 14, y += 22,20,20, "X"));
addLabel(new GuiNpcLabel(9, "4:", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(9, guiLeft + 36, y, 170, 20, getTitle(spawn.compound4)));
this.addButton(new GuiNpcButton(29, guiLeft + 14, y += 22,20,20, "X"));
addLabel(new GuiNpcLabel(10, "5:", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(10, guiLeft + 36, y, 170, 20, getTitle(spawn.compound5)));
addButton(new GuiNpcButton(21, guiLeft + 6, y += 20, 20, 20, "+"));
if (this.spawnEntryScroll.hasSelected()) {
int selected = Integer.parseInt(this.spawnEntryScroll.getSelected());
addButton(new GuiNpcButton(22, guiLeft + 32, y, 20, 20, "-"));
addTextField(new GuiNpcTextField(25, this, guiLeft + 60, y += 10, 30, 20, String.valueOf(selected)));
addButton(new GuiNpcButton(26, guiLeft + 92, y, 100, 20, this.getTitle(this.spawn.spawnCompounds.get(selected))));
}
}
private String getTitle(NBTTagCompound compound) {
if(compound != null && compound.hasKey("ClonedName"))
return compound.getString("ClonedName");
return "gui.selectnpc";
}
@@ -99,84 +102,105 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
SpawnData spawn = new SpawnData();
spawn.name = name;
Client.sendData(EnumPacketServer.NaturalSpawnSave, spawn.writeNBT(new NBTTagCompound()));
this.spawnEntryScroll.selected = -1;
}
if(id == 2){
if(data.containsKey(scroll.getSelected())) {
if(data.containsKey(scrollNaturalSpawns.getSelected())) {
Client.sendData(EnumPacketServer.NaturalSpawnRemove, spawn.id);
spawn = new SpawnData();
scroll.clear();
scrollNaturalSpawns.clear();
this.spawnEntryScroll.selected = -1;
}
}
if(id == 3){
setSubGui(new SubGuiNpcBiomes(spawn));
}
if(id == 11){
setSubGui(new SubGuiNpcDimensions(spawn));
}
if(id == 4){
setSubGui(new SubGuiSpawningOptions(spawn));
}
if(id >= 6 && id <= 10){
slotSelected = id - 5;
if (id == 21) {
int addId = 0;
if (this.spawnEntryScroll.hasSelected()) {
int selected = Integer.parseInt(spawnEntryScroll.getSelected());
ArrayList<Integer> keys = new ArrayList<>(this.spawn.spawnCompounds.keySet());
int keyIndex = keys.indexOf(selected);
do {
addId = keys.get(keyIndex) + 1;
keyIndex++;
} while (this.spawn.spawnCompounds.containsKey(addId));
} else if (this.spawn.spawnCompounds.size() > 0) {
addId = (Integer) this.spawn.spawnCompounds.keySet().toArray()[this.spawn.spawnCompounds.size() - 1] + 1;
}
this.spawn.spawnCompounds.put(addId, new NBTTagCompound());
this.initGui();
}
if (id == 22) {
if (this.spawnEntryScroll.hasSelected()) {
int selected = Integer.parseInt(spawnEntryScroll.getSelected());
this.spawn.spawnCompounds.remove(selected);
this.spawnEntryScroll.selected = -1;
this.initGui();
}
}
if (id == 26) {
setSubGui(new GuiNpcMobSpawnerSelector());
}
if(id == 25){
spawn.compound1 = new NBTTagCompound();
initGui();
}
if(id == 26){
spawn.compound2 = new NBTTagCompound();
initGui();
}
if(id == 27){
spawn.compound3 = new NBTTagCompound();
initGui();
}
if(id == 28){
spawn.compound4 = new NBTTagCompound();
initGui();
}
if(id == 29){
spawn.compound5 = new NBTTagCompound();
initGui();
}
}
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
String name = guiNpcTextField.getText();
if(name.isEmpty() || data.containsKey(name)){
guiNpcTextField.setText(spawn.name);
public void unFocused(GuiNpcTextField textfield) {
if (textfield.id == 1) {
String name = textfield.getText();
if (name.isEmpty() || data.containsKey(name)) {
textfield.setText(spawn.name);
} else {
String old = spawn.name;
data.remove(old);
spawn.name = name;
data.put(spawn.name, spawn.id);
scrollNaturalSpawns.replace(old, spawn.name);
}
}
else{
String old = spawn.name;
data.remove(old);
spawn.name = name;
data.put(spawn.name, spawn.id);
scroll.replace(old, spawn.name);
if (textfield.id == 25 && this.spawnEntryScroll.hasSelected()) {
int selected = Integer.parseInt(spawnEntryScroll.getSelected());
if (spawnEntryScroll.getList().contains(String.valueOf(textfield.getInteger()))) {
textfield.setText(String.valueOf(selected));
return;
}
NBTTagCompound compound = spawn.spawnCompounds.get(selected);
spawn.spawnCompounds.remove(selected);
spawn.spawnCompounds.put(textfield.getInteger(), compound);
spawnEntryScroll.selected = -1;
initGui();
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
String name = scroll.getSelected();
String name = scrollNaturalSpawns.getSelected();
this.data = data;
scroll.setList(list);
scrollNaturalSpawns.setList(list);
if(name != null)
scroll.setSelected(name);
scrollNaturalSpawns.setSelected(name);
initGui();
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if(guiCustomScroll.id == 0){
if (guiCustomScroll.id == 0){
save();
String selected = scroll.getSelected();
String selected = scrollNaturalSpawns.getSelected();
spawn = new SpawnData();
Client.sendData(EnumPacketServer.NaturalSpawnGet, data.get(selected));
}
if (guiCustomScroll.id == 20) {
initGui();
}
}
@Override
@@ -188,33 +212,14 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
@Override
public void setSelected(String selected) {
}
public void closeSubGui(SubGuiInterface gui) {
super.closeSubGui(gui);
if(gui instanceof GuiNpcMobSpawnerSelector){
if(gui instanceof GuiNpcMobSpawnerSelector && this.spawnEntryScroll.hasSelected()){
GuiNpcMobSpawnerSelector selector = (GuiNpcMobSpawnerSelector) gui;
NBTTagCompound compound = selector.getCompound();
if (compound != null) {
switch (slotSelected) {
case 1:
spawn.compound1 = compound;
break;
case 2:
spawn.compound2 = compound;
break;
case 3:
spawn.compound3 = compound;
break;
case 4:
spawn.compound4 = compound;
break;
case 5:
spawn.compound5 = compound;
break;
}
}
int selected = Integer.parseInt(this.spawnEntryScroll.getSelected());
this.spawn.spawnCompounds.put(selected,selector.getCompound());
initGui();
}
}
@@ -233,13 +238,10 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
@Override
public void mousePressed(GuiNpcSlider guiNpcSlider) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(GuiNpcSlider guiNpcSlider) {
spawn.itemWeight = (int) (guiNpcSlider.sliderValue * 100);
}
}
@@ -1,4 +1,4 @@
package noppes.npcs.client.renderer;
package noppes.npcs.client.renderer.customitem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.client.Client;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
@@ -46,31 +47,10 @@ public class CustomItemRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
InputStream inputstream = null;
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1) {
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(scriptCustomItem.texture));
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
scriptCustomItem.width = bufferedimage.getWidth();
scriptCustomItem.height = bufferedimage.getHeight();
scriptCustomItem.saveItemData();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputstream != null) {
inputstream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1)
ImageData imageData = Client.getImageData(scriptCustomItem.texture);
if(imageData.getTotalWidth() == -1 || imageData.getTotalHeight() == -1)
return;
if (type == ItemRenderType.INVENTORY) {
@@ -150,7 +130,7 @@ public class CustomItemRenderer implements IItemRenderer {
int pass = 0;
GL11.glPushMatrix();
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
Tessellator tessellator = Tessellator.instance;
@@ -206,7 +186,8 @@ public class CustomItemRenderer implements IItemRenderer {
// Makes items offset when in 3D, like when in 2D, looks much better. Considered a vanilla bug...
GL11.glTranslatef(0f, 0f, f9 + f10);
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, scriptCustomItem.width, scriptCustomItem.height, f9);
ImageData imageData = Client.getImageData(scriptCustomItem.texture);
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, imageData.getTotalWidth(), imageData.getTotalHeight(), f9);
if (itemStack.hasEffect(pass))
{
@@ -305,7 +286,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
renderCustomItemSlot(0,0,16,16, itemRed, itemGreen, itemBlue);
@@ -381,7 +362,7 @@ public class CustomItemRenderer implements IItemRenderer {
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
texturemanager.bindTexture(location);
Tessellator tessellator = Tessellator.instance;
@@ -437,8 +418,9 @@ public class CustomItemRenderer implements IItemRenderer {
public static void renderCustomItemIn2D(ItemStack itemStack, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_)
{
int width = ItemScripted.GetWrapper(itemStack).width;
int height = ItemScripted.GetWrapper(itemStack).height;
ImageData imageData = Client.getImageData(ItemScripted.GetWrapper(itemStack).texture);
int width = imageData.getTotalWidth();
int height = imageData.getTotalHeight();
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, 0.0F, 1.0F);
@@ -0,0 +1,119 @@
package noppes.npcs.client.renderer.customitem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
public class ImageData {
private ResourceLocation location;
private final boolean isUrl;
private ImageDownloadAlt imageDownloadAlt = null;
private BufferedImage bufferedImage = null;
private int totalWidth, totalHeight;
private boolean gotWidthHeight;
public ImageData(String directory) {
this.location = new ResourceLocation(directory);
if (directory.startsWith("https://")) {
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true, false));
texturemanager.loadTexture(location, this.imageDownloadAlt);
} else {
this.isUrl = false;
}
}
public ResourceLocation getLocation() {
return this.isUrl && this.imageDownloadAlt.getBufferedImage() == null ? null : this.location;
}
public BufferedImage getBufferedImage() {
if (this.bufferedImage == null) {
if (!this.isUrl) {
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(location);
InputStream inputstream = iresource.getInputStream();
this.bufferedImage = ImageIO.read(inputstream);
} catch (IOException ignored) {}
} else {
this.bufferedImage = this.imageDownloadAlt.getBufferedImage();
}
}
return this.bufferedImage;
}
private void getWidthHeight() throws IOException {
InputStream inputstream = null;
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.location);
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
this.gotWidthHeight = true;
this.totalWidth = bufferedimage.getWidth();
this.totalHeight = bufferedimage.getHeight();
correctWidthHeight();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputstream != null) {
inputstream.close();
}
}
}
private void getURLWidthHeight(){
if(this.imageDownloadAlt.getBufferedImage() != null) {
this.gotWidthHeight = true;
this.totalWidth = this.imageDownloadAlt.getBufferedImage().getWidth();
this.totalHeight = this.imageDownloadAlt.getBufferedImage().getHeight();
correctWidthHeight();
}
}
private void correctWidthHeight(){
this.totalWidth = Math.max(this.totalWidth, 1);
this.totalHeight = Math.max(this.totalHeight, 1);
}
public int getTotalWidth() {
if (!this.gotWidthHeight) {
try {
if (!this.isUrl) {
this.getWidthHeight();
} else {
this.getURLWidthHeight();
}
} catch (Exception ignored) {}
if (!this.gotWidthHeight) {
return -1;
}
}
return this.totalWidth;
}
public int getTotalHeight() {
if (!this.gotWidthHeight) {
try {
if (!this.isUrl) {
this.getWidthHeight();
} else {
this.getURLWidthHeight();
}
} catch (Exception ignored) {}
if (!this.gotWidthHeight) {
return -1;
}
}
return this.totalHeight;
}
}
@@ -168,10 +168,20 @@ public class SpawnController implements INaturalSpawnsHandler {
return biomes.get(biome);
}
public SpawnData getRandomSpawnData(String biome, boolean isAir) {
List<SpawnData> list = getSpawnList(biome);
if(list == null || list.isEmpty())
public SpawnData getRandomSpawnData(String biome, int dimensionId) {
List<SpawnData> biomeList = getSpawnList(biome);
if (biomeList == null)
return null;
ArrayList<SpawnData> list = new ArrayList<>();
for (SpawnData data : biomeList) {
if (data.dimensions.contains(dimensionId)) {
list.add(data);
}
}
if(list.isEmpty())
return null;
return (SpawnData) WeightedRandom.getRandomItem(this.random, list);
}
@@ -4,27 +4,23 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.WeightedRandom;
import net.minecraftforge.common.DimensionManager;
import noppes.npcs.NBTTags;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.handler.data.INaturalSpawn;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
public List<String> biomes = new ArrayList<String>();
public List<String> biomes = new ArrayList<>();
public HashSet<Integer> dimensions = new HashSet<>();
public int id = -1;
public String name = "";
public NBTTagCompound compound1 = new NBTTagCompound();
public NBTTagCompound compound2 = new NBTTagCompound();
public NBTTagCompound compound3 = new NBTTagCompound();
public NBTTagCompound compound4 = new NBTTagCompound();
public NBTTagCompound compound5 = new NBTTagCompound();
public HashMap<Integer,NBTTagCompound> spawnCompounds = new HashMap<>();
public boolean animalSpawning = true;
public boolean monsterSpawning = false;
@@ -32,7 +28,7 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
public boolean airSpawning = false;
public int spawnHeightMin;
public int spawnHeightMax;
public int spawnHeightMax = 100;
public SpawnData() {
super(10);
@@ -46,11 +42,20 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
itemWeight = 1;
biomes = NBTTags.getStringList(compound.getTagList("SpawnBiomes", 10));
compound1 = compound.getCompoundTag("SpawnCompound1");
compound2 = compound.getCompoundTag("SpawnCompound2");
compound3 = compound.getCompoundTag("SpawnCompound3");
compound4 = compound.getCompoundTag("SpawnCompound4");
compound5 = compound.getCompoundTag("SpawnCompound5");
if (!compound.hasKey("SpawnDimensions")) {
dimensions.addAll(Arrays.asList(DimensionManager.getStaticDimensionIDs()));
} else {
dimensions = NBTTags.getIntegerSet(compound.getTagList("SpawnDimensions", 10));
}
this.spawnCompounds.clear();
Set<?> keys = compound.func_150296_c();
for (Object key : keys) {
if (((String)key).startsWith("SpawnCompound")) {
int i = Integer.parseInt(((String)key).replace("SpawnCompound",""));
this.spawnCompounds.put(i,compound.getCompoundTag("SpawnCompound"+i));
}
}
animalSpawning = compound.getBoolean("AnimalSpawning");
monsterSpawning = compound.getBoolean("MonsterSpawning");
@@ -71,11 +76,14 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
compound.setInteger("SpawnWeight", itemWeight);
compound.setTag("SpawnBiomes", NBTTags.nbtStringList(biomes));
compound.setTag("SpawnCompound1", compound1);
compound.setTag("SpawnCompound2", compound2);
compound.setTag("SpawnCompound3", compound3);
compound.setTag("SpawnCompound4", compound4);
compound.setTag("SpawnCompound5", compound5);
if (!this.dimensions.isEmpty()) {
compound.setTag("SpawnDimensions", NBTTags.nbtIntegerSet(dimensions));
}
Set<Map.Entry<Integer,NBTTagCompound>> entries = this.spawnCompounds.entrySet();
for (Map.Entry<Integer,NBTTagCompound> entry : entries) {
compound.setTag("SpawnCompound"+entry.getKey(),entry.getValue());
}
compound.setBoolean("AnimalSpawning", animalSpawning);
compound.setBoolean("MonsterSpawning", monsterSpawning);
@@ -98,73 +106,30 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
}
public void setEntity(IEntity entity, int slot) {
if (slot < 1)
slot = 1;
if (slot > 5)
slot = 5;
NBTTagCompound compound = new NBTTagCompound();
if (entity != null && !entity.getMCEntity().writeToNBTOptional(compound)) {
throw new CustomNPCsException("Entity could not be written to NBT");
} else {
switch (slot) {
case 1:
ServerCloneController.Instance.cleanTags(compound1);
compound1 = compound;
break;
case 2:
ServerCloneController.Instance.cleanTags(compound2);
compound2 = compound;
break;
case 3:
ServerCloneController.Instance.cleanTags(compound3);
compound3 = compound;
break;
case 4:
ServerCloneController.Instance.cleanTags(compound4);
compound4 = compound;
break;
case 5:
ServerCloneController.Instance.cleanTags(compound5);
compound5 = compound;
break;
}
this.spawnCompounds.put(slot,compound);
}
}
public IEntity getEntity(IWorld world, int slot) {
if (slot < 1)
slot = 1;
if (slot > 5)
slot = 5;
if (!this.spawnCompounds.containsKey(slot)) {
return null;
}
try {
NBTTagCompound compound = new NBTTagCompound();
switch (slot) {
case 1:
compound = compound1;
break;
case 2:
compound = compound2;
break;
case 3:
compound = compound3;
break;
case 4:
compound = compound4;
break;
case 5:
compound = compound5;
break;
}
Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld());
Entity entity = EntityList.createEntityFromNBT(this.spawnCompounds.get(slot), world.getMCWorld());
return NpcAPI.Instance().getIEntity(entity);
} catch (Exception e) {
throw new CustomNPCsException("Error creating entity from spawn data:\n" + e.getMessage());
}
}
public Integer[] getSlots() {
return this.spawnCompounds.keySet().toArray(new Integer[0]);
}
public void setWeight(int weight) {
if (weight < 1)
weight = 1;
@@ -38,7 +38,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
public int enchantability;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public int width = -1, height = -1;
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
@@ -393,9 +392,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
compound.setFloat("TranslateY",this.translateY);
compound.setFloat("TranslateZ",this.translateZ);
compound.setInteger("Width", this.width);
compound.setInteger("Height", this.height);
compound.setBoolean("IsTool", this.isTool);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
@@ -432,9 +428,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
this.translateY = compound.getFloat("TranslateY");
this.translateZ = compound.getFloat("TranslateZ");
this.width = compound.getInteger("Width");
this.height = compound.getInteger("Height");
this.isTool = compound.getBoolean("IsTool");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");