From ca31cc2e36cd17aed9b7ee701dc34f552e08a879 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 22 Dec 2023 00:56:32 -0600 Subject: [PATCH] didnt fix what i wanted, but maybe fixed something? --- .../java/train/client/render/RenderRollingStock.java | 9 ++++++--- src/main/java/train/common/api/AbstractTrains.java | 8 ++++++-- src/main/java/train/common/api/TrainRecord.java | 5 +++-- src/main/java/train/common/items/ItemRollingStock.java | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/train/client/render/RenderRollingStock.java b/src/main/java/train/client/render/RenderRollingStock.java index f298830ee..b63283b06 100644 --- a/src/main/java/train/client/render/RenderRollingStock.java +++ b/src/main/java/train/client/render/RenderRollingStock.java @@ -12,6 +12,7 @@ import net.minecraft.util.Vec3; import org.lwjgl.opengl.GL11; import train.common.Traincraft; +import train.common.api.AbstractTrains; import train.common.api.EntityRollingStock; import train.common.api.Locomotive; import train.common.api.TrainRenderRecord; @@ -459,9 +460,11 @@ protected ResourceLocation getEntityTexture(Entity entity) { } public static ResourceLocation getTexture(Entity entity) { - TrainRenderRecord render = Traincraft.instance.traincraftRegistry.getTrainRenderRecord(entity.getClass()); - if (render != null) { - return render.getTextureFile(((EntityRollingStock) entity).getColor()); + if(entity instanceof AbstractTrains) { + TrainRenderRecord render = Traincraft.instance.traincraftRegistry.getTrainRenderRecord(entity.getClass()); + if (render != null) { + return render.getTextureFile(((AbstractTrains) entity).getColor()); + } } return null; } diff --git a/src/main/java/train/common/api/AbstractTrains.java b/src/main/java/train/common/api/AbstractTrains.java index 9b8971a42..3483b61f1 100644 --- a/src/main/java/train/common/api/AbstractTrains.java +++ b/src/main/java/train/common/api/AbstractTrains.java @@ -307,7 +307,7 @@ public void setColor(int color) { public void setColor(String color) { TrainRecord trainRecord = Traincraft.instance.traincraftRegistry.findTrainRecordByItem(getCartItem().getItem()); - if (trainRecord != null && trainRecord.getLiveries() != null) { + if (trainRecord != null && trainRecord.getLiveries() != null && trainRecord.getLiveries().size()>0) { if (color.equals("-1") || !trainRecord.getLiveries().contains(color)) { color = (trainRecord.getLiveries().get(trainRecord.getLiveries().indexOf(color)+1>trainRecord.getLiveries().size()-1?0:trainRecord.getLiveries().indexOf(color)+1)); } @@ -328,7 +328,11 @@ public void setRenderPitch(float pitch) { public String getColor() { entity_data.updateData(dataWatcher.getWatchableObjectString(12)); - return entity_data.getString("color"); + if(entity_data.hasString("color")) { + return entity_data.getString("color"); + } else { + return trainSpec.getLiveries().get(0); + } } @Override diff --git a/src/main/java/train/common/api/TrainRecord.java b/src/main/java/train/common/api/TrainRecord.java index 731fd96b4..b47a8df5a 100644 --- a/src/main/java/train/common/api/TrainRecord.java +++ b/src/main/java/train/common/api/TrainRecord.java @@ -1,5 +1,6 @@ package train.common.api; +import ebf.tim.utility.DebugUtil; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.world.World; @@ -94,7 +95,7 @@ public static TrainRecord makeEntry(String entryName, String internalName, Class * #param entryName is depreciated * #param additionalTooltip is depreciated. */ - public static TrainRecord makeEntry(final String entryName, final String internalName, final Class entityClass, final Item item, final String trainType, final int MHP, final int maxSpeed, final double mass, final int fuelConsumption, final int waterConsumption, final int heatingTime, final double accelerationRate, final double brakeRate, final int tankCapacity, final int cargoCapacity, final String[] colors, final int guiRenderScale, final double bogieLocoPositions, final String additionnalTooltip) { + public static TrainRecord makeEntry(final String entryName, final String internalName, final Class entityClass, final Item item, final String trainType, final int MHP, final int maxSpeed, final double mass, final int fuelConsumption, final int waterConsumption, final int heatingTime, final double accelerationRate, final double brakeRate, final int tankCapacity, final int cargoCapacity, final String[] colors, int guiRenderScale, final double bogieLocoPositions, final String additionnalTooltip) { return new TrainRecord() { @Override public String getName() { @@ -163,7 +164,7 @@ public int getTankCapacity() { @Override public List getColors() { - if (colors == null) { + if (colors == null || colors.length==0) { return new ArrayList<>(); } else { return Arrays.asList(colors); diff --git a/src/main/java/train/common/items/ItemRollingStock.java b/src/main/java/train/common/items/ItemRollingStock.java index 0559df896..b9875acb1 100644 --- a/src/main/java/train/common/items/ItemRollingStock.java +++ b/src/main/java/train/common/items/ItemRollingStock.java @@ -198,7 +198,7 @@ public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, if (par3World.isRemote) { return false; } - if(tileentity!=null && tileentity instanceof TileTCRail){ + if(tileentity instanceof TileTCRail){ TileTCRail tile = (TileTCRail) tileentity; if (tile.getType().equals(TrackTypes.SMALL_STRAIGHT.getLabel()) ||tile.getType().equals(TrackTypes.MEDIUM_STRAIGHT.getLabel()) @@ -229,7 +229,7 @@ public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, par2EntityPlayer.addChatMessage(new ChatComponentText("Place me on a straight piece of track !")); return false; } - else if(tileentity!=null && tileentity instanceof TileTCRailGag){ + else if(tileentity instanceof TileTCRailGag){ TileTCRailGag tileGag = (TileTCRailGag) tileentity; TileTCRail tile = (TileTCRail) par3World.getTileEntity(tileGag.originX, tileGag.originY, tileGag.originZ);