Skip to content

Commit

Permalink
too many API bugs
Browse files Browse the repository at this point in the history
- lots of skin rework stuff. changes are probably for the better but would have been nice to not be necessary.
- fixed a couple crashes
- fixed a number of hard reliances on the train spec, which will be null when using the TC5-style.
  • Loading branch information
EternalBlueFlame committed Sep 27, 2024
1 parent f85838a commit 17094a2
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 235 deletions.
54 changes: 50 additions & 4 deletions src/main/java/ebf/tim/api/SkinRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,63 @@
import train.common.api.AbstractTrains;
import train.common.library.TraincraftRegistry;

@Deprecated
import java.util.*;


public class SkinRegistry {

public static Map<Class<? extends AbstractTrains>, List<String>> liveryMap = new HashMap<Class<? extends AbstractTrains>, List<String>>();

public static List<String> get(AbstractTrains t){
if(liveryMap.containsKey(t.getClass())) {
return liveryMap.get(t.getClass());
} else {
return new ArrayList<String>();
}
}

public static void addSkin(Class<? extends AbstractTrains> train, TransportSkin str){
Traincraft.instance.traincraftRegistry.addLivery(train,str.addr);
if(!liveryMap.containsKey(train)) {
liveryMap.put(train, Collections.singletonList(str.addr));
} else {
List<String> temp = new ArrayList<>();
temp.addAll(liveryMap.get(train));
temp.add(str.addr);
liveryMap.put(train,temp);
}
}

public static void addSkin(Class<? extends AbstractTrains> train, String str){
if(!liveryMap.containsKey(train)) {
liveryMap.put(train, Collections.singletonList(str));
} else {
List<String> temp = new ArrayList<>();
temp.addAll(liveryMap.get(train));
temp.add(str);
liveryMap.put(train,temp);
}
}

public static void addSkin(Class<? extends AbstractTrains> train, String modid,String addr,String[] bogieSkins,String name, String description){
Traincraft.instance.traincraftRegistry.addLivery(train,modid+":"+addr);
if(!liveryMap.containsKey(train)) {
liveryMap.put(train, Collections.singletonList(modid+":"+addr));
} else {
List<String> temp = new ArrayList<>();
temp.addAll(liveryMap.get(train));
temp.add(modid+":"+addr);
liveryMap.put(train,temp);
}
}

public static void addSkin(Class<? extends AbstractTrains> train, String modid,String addr,String bogieSkin,String name, String description){
Traincraft.instance.traincraftRegistry.addLivery(train,modid+":"+addr);
if(!liveryMap.containsKey(train)) {
liveryMap.put(train, Collections.singletonList(modid+":"+addr));
} else {
List<String> temp = new ArrayList<>();
temp.addAll(liveryMap.get(train));
temp.add(modid+":"+addr);
liveryMap.put(train,temp);
}
}

}
6 changes: 4 additions & 2 deletions src/main/java/fexcraft/tmt/slim/TextureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TextureManager {
*/
public static int bindTexture(ResourceLocation textureURI) {
if (textureURI == null){
Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(Info.modID,"nullTrain"));
GL11.glBindTexture(GL_TEXTURE_2D, TextureUtil.missingTexture.getGlTextureId());
return 0;
}
//clean out the texture bind map when texturepacks are reloaded.
Expand Down Expand Up @@ -204,7 +204,9 @@ public static int[] postProcessColor(int newColor, int r, int g, int b){


public static boolean textureExists(ResourceLocation textureURI){

if(textureURI==null){
return false;
}
object = Minecraft.getMinecraft().getTextureManager().getTexture(textureURI);
if (object == null) {
object = new SimpleTexture(textureURI);
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/train/client/gui/GuiPaintbrushMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ebf.tim.api.SkinRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
Expand Down Expand Up @@ -111,7 +112,7 @@ public GuiPaintbrushMenu(EntityPlayer editingPlayer, EntityRollingStock rollingS
throw new RuntimeException(e);
}
record = rollingStock.getSpec();
totalOptions = rollingStock.getSpec().getLiveries().size();
totalOptions = SkinRegistry.get(rollingStock).size();
for (int i = 0; i < totalOptions; i++) { // Set page to the page with the currently selected texture.
if (record.getLiveries().get(i).equals(rollingStock.getColor())) {
currentDisplayTexture = i;
Expand Down Expand Up @@ -160,8 +161,8 @@ public void initGui() {
this.lastNonSkins=buttonList.size();
int entry = lastNonSkins+2;
int amt = MAX_LISTED_SKINS;
if (amt > rollingStock.getSpec().getLiveries().size()) {
amt = rollingStock.getSpec().getLiveries().size();
if (amt > SkinRegistry.get(rollingStock).size()) {
amt = SkinRegistry.get(rollingStock).size();
}
for(int i=0;i<amt;i++) {
this.buttonList.add(new GuiButtonPaintbrushMenu(entry,GUI_ANCHOR_X + 80 + 64, GUI_ANCHOR_Y + 10+yOffset,128,16, GuiButtonPaintbrushMenu.Type.SKINS));
Expand Down Expand Up @@ -201,7 +202,7 @@ private void updateButtons() {
this.skinListArrowUp.visible = true;
this.skinListArrowUp.showButton = (this.drawList && topVisSkin > 0);
this.skinListArrowDown.visible = true;
this.skinListArrowDown.showButton = (this.drawList && topVisSkin+10 < rollingStock.getSpec().getLiveries().size());
this.skinListArrowDown.showButton = (this.drawList && topVisSkin+10 < SkinRegistry.get(rollingStock).size());
this.skinListDropdown.showButton = true;
this.skinListDropdown.visible = true;
this.renderModelsButton.visible = true;
Expand Down Expand Up @@ -354,8 +355,8 @@ public void drawScreen(int mouseX, int mouseY, float par3) {
} else {
int yOffset = 22;
for (int i=0;i<MAX_LISTED_SKINS;i++) {
if(i+topVisSkin<rollingStock.getSpec().getLiveries().size()) {
String t = rollingStock.getSpec().getLiveries().get(i + topVisSkin);
if(i+topVisSkin<SkinRegistry.get(rollingStock).size()) {
String t = SkinRegistry.get(rollingStock).get(i + topVisSkin);
fontRendererObj.drawString(t, GUI_ANCHOR_MID_X - ((int) (fontRendererObj.getStringWidth(t) * 0.5)), GUI_ANCHOR_Y + 10 + yOffset, 0);
yOffset += 16;
}
Expand Down Expand Up @@ -537,8 +538,8 @@ protected void actionPerformed(GuiButton clickedButton) {
break;
default:
if(clickedButton.id >= this.lastNonSkins && drawList) {
currentDisplayTexture = rollingStock.getSpec().getLiveries().indexOf(
rollingStock.getSpec().getLiveries().get(this.buttonList.indexOf(clickedButton)-this.lastNonSkins+topVisSkin));
currentDisplayTexture = SkinRegistry.get(rollingStock).indexOf(
SkinRegistry.get(rollingStock).get(this.buttonList.indexOf(clickedButton)-this.lastNonSkins+topVisSkin));
drawList = !drawList;
renderModels = !renderModels;
updateSelectedTextureProperties();
Expand All @@ -561,7 +562,7 @@ public void handleMenuScroll(int i) {
updateButtons();
}
} else {
if(topVisSkin+10 < rollingStock.getSpec().getLiveries().size()) {
if(topVisSkin+10 < SkinRegistry.get(rollingStock).size()) {
topVisSkin++;
updateButtons();
}
Expand Down Expand Up @@ -634,7 +635,7 @@ public static Integer getActiveButtonID() {

private void updateSelectedTextureProperties() {
descriptionScrollerIndex = 0;
currentDisplayTextureString = rollingStock.getSpec().getLiveries().get(currentDisplayTexture);
currentDisplayTextureString = SkinRegistry.get(rollingStock).get(currentDisplayTexture);
String currentDisplayTextureDescriptionString;
if (rollingStock.textureDescriptionMap.containsKey(currentDisplayTextureString)) {
if (rollingStock.textureDescriptionMap.get(currentDisplayTextureString).title != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/train/client/render/RenderRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static void renderTheMinecart(EntityRollingStock cart, double x, double y
double var15 = cart.lastTickPosX + (cart.posX - cart.lastTickPosX) * time;
double var17 = cart.lastTickPosY + (cart.posY - cart.lastTickPosY) * time;
double var19 = cart.lastTickPosZ + (cart.posZ - cart.lastTickPosZ) * time;
Vec3 var23 = cart.func_70489_a(var15, var17, var19);
Vec3 var23 = cart.worldObj==null?null:cart.func_70489_a(var15, var17, var19);
float pitch = cart.prevRotationPitch + (cart.rotationPitch - cart.prevRotationPitch) * time;
Vec3 renderYVect = cart.yVector(var15, var17, var19);//only on TC rails
Vec3 renderYVect = cart.worldObj==null?null:cart.yVector(var15, var17, var19);//only on TC rails
if (var23 != null) {
Vec3 var25 = cart.func_70495_a(var15, var17, var19, 0.30000001192092896D);
Vec3 var26 = cart.func_70495_a(var15, var17, var19, -0.30000001192092896D);
Expand Down Expand Up @@ -187,7 +187,7 @@ public static void renderTheMinecart(EntityRollingStock cart, double x, double y
}

GL11.glEnable(GL11.GL_LIGHTING);
int skyLight = cart.worldObj.getLightBrightnessForSkyBlocks(i, j, k, 0);
int skyLight = cart.worldObj==null?0:cart.worldObj.getLightBrightnessForSkyBlocks(i, j, k, 0);
if (!renderModeGUI) {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, skyLight % 65536,
skyLight / 65536f);
Expand All @@ -206,7 +206,7 @@ public static void renderTheMinecart(EntityRollingStock cart, double x, double y
if(cart.getModel()[m].getTrans()!=null){
GL11.glTranslatef(cart.getModel()[m].getTrans()[0],cart.getModel()[m].getTrans()[1],cart.getModel()[m].getTrans()[2]);
}
else if(cart.modelOffsets()[m]!=null) {
else if(cart.modelOffsets()!=null &&cart.modelOffsets()[m]!=null) {
GL11.glTranslatef(cart.modelOffsets()[m][0], cart.modelOffsets()[m][1], cart.modelOffsets()[m][2]);
}
if(cart.getModel()[m].getRotate()!=null){
Expand Down
Loading

0 comments on commit 17094a2

Please sign in to comment.