Skip to content

Commit

Permalink
Merge 'origin/1.7-TiM' into 1.12.2-TiM
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalBlueFlame committed Sep 11, 2023
2 parents bf819cb + 5fc3418 commit 20241b4
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ebf/tim/TrainsInMotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public void init(FMLInitializationEvent event) {
TrainsInMotion.keyChannel.registerMessage(HANDLERS[5], PacketCraftingPage.class, 6, Side.SERVER);
TrainsInMotion.updateChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TiM.update");
TrainsInMotion.updateChannel.registerMessage(HANDLERS[6], PacketUpdateClients.class, 7, Side.CLIENT);
TrainsInMotion.updateChannel.registerMessage(PacketSeatUpdate.Handler.class, PacketSeatUpdate.class, 8, Side.CLIENT);
TrainsInMotion.updateChannel.registerMessage(PacketSeatUpdate.Handler.class, PacketSeatUpdate.class, 9, Side.SERVER);
TrainsInMotion.trackChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TiM.track");


Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ebf/tim/entities/EntitySeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -141,9 +142,9 @@ public void writeSpawnData(ByteBuf buffer) {
}

@Override
public void updatePassenger(Entity passenger) {
if (this.isPassenger(passenger)) {
passenger.setPosition(this.posX, this.posY-1, this.posZ);
public void updateRiderPosition() {
if (this.getPassenger() != null) {
this.getPassenger().setPosition(this.posX, this.posY+(getWorld().isRemote?(this.getPassenger()==Minecraft.getMinecraft().thePlayer?0.4:-1.3):-1.5), this.posZ);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ebf/tim/entities/GenericRailTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class GenericRailTransport extends EntityMinecart implements IEntityAddit
/**calculated movement speed, first value is used for GUI and speed, second is used for render effects.*/
@Deprecated //TODO: value 1 gets the number right more often, but value 2 gets direction right. HOW
public float[] velocity=new float[]{0,0};
public int forceBackupTimer =0, syncTimer=0;
public int forceBackupTimer =0, syncTimer=0, deathTick=0;
public float pullingWeight=0;

private float ticksSinceLastVelocityChange=1;
Expand Down Expand Up @@ -663,7 +663,8 @@ public boolean attackEntityFrom(DamageSource damageSource, float p_70097_2_){
}

//on Destruction
if (health<1){
if (health<1 && !getWorld().isRemote && deathTick==0){
deathTick=this.ticksExisted;
//since it was a player be sure we remove the entity from the logging.
ServerLogger.deleteWagon(this);
//be sure we drop the inventory items on death.
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/ebf/tim/gui/GUIPaintBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import ebf.tim.TrainsInMotion;
import ebf.tim.api.SkinRegistry;
import ebf.tim.api.TransportSkin;
import ebf.tim.entities.GenericRailTransport;
import ebf.tim.networking.PacketPaint;
Expand Down Expand Up @@ -66,6 +67,8 @@ public int compare(TransportSkin o1, TransportSkin o2) {
skinList.add(s.modid + ":" + s.name);
}
}
currentTransportSkin = entity.getCurrentSkin();
page = skinList.indexOf(currentTransportSkin.modid + ":" + currentTransportSkin.getName());
}

Keyboard.enableRepeatEvents(true);
Expand Down Expand Up @@ -113,7 +116,7 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
public boolean doesGuiPauseGame() {return true;}


/** adds the correct buttons based on which case happens*/
/** adds the correct buttons based on which case happens*/
public void defineButtons(){
switch (guiScreen){
case 0:{
Expand All @@ -136,7 +139,7 @@ public void onClick() {
);

buttonList.add(
new GUIButton( percentLeft(75)-10,percentTop(56), 20,20,">>") {
new GUIButton( percentLeft(75)-7,percentTop(56), 20,20,">>") {
@Override
public String getHoverText() {
return "Next Page";
Expand Down Expand Up @@ -178,7 +181,7 @@ public void onClick() {


buttonList.add(
new GUIButton( percentLeft(75)-16,percentTop(45), 64,20, "Close") {
new GUIButton( percentLeft(75)-7,percentTop(45), 64,20, "Close") {
@Override
public String getHoverText() {
return "Close Menu";
Expand All @@ -192,6 +195,27 @@ public void onClick() {
public FontRenderer getFont(){return fontRenderer;}
}
);
buttonList.add(
new GUIButton(percentLeft(75)-7, percentTop(34), 40, 20, "Random") {
@Override
public String getHoverText() {
return "Randomize Skin";
}

@Override
public void onClick() {
TransportSkin random = SkinRegistry.getTransportSkins(entity.getClass()).get(SkinRegistry.getTransportSkins(entity.getClass()).keySet().toArray()[new Random().nextInt(SkinRegistry.getTransportSkins(entity.getClass()).keySet().size())]);
page = skinList.indexOf(random.modid + ":" + random.getName());
TrainsInMotion.keyChannel.sendToServer(new PacketPaint(skinList.get(page), entity.getEntityId()));
mc.displayGuiScreen(null);
}

@Override
public FontRenderer getFont() {
return fontRendererObj;
}
}
);
break;
}
}
Expand Down
175 changes: 175 additions & 0 deletions src/main/java/ebf/tim/gui/GUISeatManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package ebf.tim.gui;

import ebf.tim.TrainsInMotion;
import ebf.tim.entities.EntitySeat;
import ebf.tim.entities.GenericRailTransport;
import ebf.tim.networking.PacketSeatUpdate;
import ebf.tim.utility.ClientUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
import org.lwjgl.opengl.GL11;

import javax.vecmath.Vector2f;
import java.util.*;


/**
* <h1>Transport GUI</h1>
* used to draw the GUI for choosing a seat while in a piece of rollingstock (get here from a button in the normal UI).
* @author broscolotos
*/
public class GUISeatManager extends GUIPaintBucket {

public ArrayList<Integer> filledSeatIDs = new ArrayList<>();
public EntitySeat currentSeat;

public ArrayList<Vector2f> locations;
public GUISeatManager(GenericRailTransport transport) {
super(transport);
}

@Override
public void initGui() {
if(entity !=null && entity.getRiderOffsets().length > 0) {

}
}
@Override
public void updateScreen() {}

public static int percentTop(int value){return (int)(guiTop*(value*0.01f));}
public static int percentLeft(int value){return (int)(guiLeft*(value*0.01f));}

@Override
public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
this.drawDefaultBackground();
super.drawScreen(parWidth, parHeight, p_73863_3_);
locations = new ArrayList<>();
guiLeft=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledWidth();
guiTop=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledHeight();

if (entity.getRiderOffsets().length==0 || entity.getRiderOffsets() == null){
return;
}
for(EntitySeat seat : entity.seats) {
if (seat.getPassenger() != null) {
if (seat.getPassenger() == Minecraft.getMinecraft().thePlayer) {
currentSeat = seat;
}
filledSeatIDs.add(seat.getEntityId());
}
}
if(filledSeatIDs.size() == entity.seats.size()) { //remove after GUI is sorted out
return;
}
switch(guiScreen) {
case 0:{defineButtons();guiSeatManager();break;}
}
}
@Override
public boolean doesGuiPauseGame() {return false;}
@Override
public void defineButtons(){
switch (guiScreen){
case 0:{
buttonList =new ArrayList();
int column = 0;
int activeRow = 0;
for (int i=0;i<entity.getRiderOffsets().length; i++) {
if (percentTop(25) + (28 * activeRow + 1) - 10 > percentTop(60)) {
column++;
activeRow = 0;
}
activeRow++;
}
int totalColumns = column;
column = 0;
activeRow =0;
for (int i=0;i<entity.getRiderOffsets().length; i++) {
if (percentTop(25)+(28*activeRow+1)-10>percentTop(60)) {
column++;
activeRow=0;
}
int width = fontRendererObj.getStringWidth("Empty Seat") + 6;
if (entity.seats.get(i).getPassenger() instanceof EntityPlayer) {

if (fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) > width) {
width = fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) + 7;
if(width%2 !=0)
width++;
}
buttonList.add(
new GUIButton(percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,20,entity.seats.get(i).getPassenger().getCommandSenderName()) {
@Override
public String getHoverText() {
return "Seat is currently occupied";
}
@Override
public void onClick() {}
@Override
public FontRenderer getFont(){return fontRendererObj;}
}
);
} else { //TODO: add an else if for things that aren't players. this becomes important for stuff like stock cars or putting villagers in player seats
buttonList.add(
new GUIButton( percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,20,"Empty Seat") {
@Override
public String getHoverText() {
return "Seat is currently Empty";
}
@Override
public void onClick() {
TrainsInMotion.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this)));

}
@Override
public FontRenderer getFont(){return fontRendererObj;}
}
);
}
locations.add(new Vector2f(percentLeft(50)-88-(totalColumns/2)+(column*120)-(width/2),percentTop(25)+(28*activeRow+1)-13));
activeRow++;
}
buttonList.add(
new GUIButton( percentLeft(50)-((fontRendererObj.getStringWidth("Close")+7)/2), percentTop(75)-10, fontRendererObj.getStringWidth("Close")+7,20,"Close") {
@Override
public String getHoverText() {
return "Close Inventory";
}
@Override
public void onClick() {
mc.displayGuiScreen(null);
}
@Override
public FontRenderer getFont(){return fontRendererObj;}
}
);
break;
}
}
}




public void guiSeatManager(){
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPushMatrix();
mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory);
for(Vector2f pos : locations) {
ClientUtil.drawTexturedRect(pos.x-3, pos.y-3, 54, 51, 30, 30, 20, 20);
}

for(EntitySeat seat: entity.seats) {
if (seat.getPassenger() instanceof AbstractClientPlayer) {
mc.getTextureManager().bindTexture(((AbstractClientPlayer) seat.getPassenger()).getLocationSkin());
ClientUtil.drawTexturedRect(locations.get(entity.seats.indexOf(seat)).x, locations.get(entity.seats.indexOf(seat)).y, 32, 64, 24, 24, 32, 64);
}
}
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
}
}
39 changes: 31 additions & 8 deletions src/main/java/ebf/tim/gui/GUITransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public void onClick() {
@Override
public FontRenderer getFont(){return fontRenderer;}
});

this.buttons.add(new GUIButton((int)guiLeft + 238, (int)guiTop + 166, 18, 18){

@Override
Expand Down Expand Up @@ -270,6 +269,27 @@ public void onClick() {
@Override
public FontRenderer getFont(){return fontRenderer;}
});
if (transport.getRiderOffsets().length > 0 || transport.getRiderOffsets() != null) {
this.buttons.add(new GUIButton((int)guiLeft+166,(int)guiTop+166, 18,18) {
@Override
public String getHoverText() {
return "gui.seats";
}

@Override
public int[] getColor(){
return null;
}

@Override
public void onClick() {
TrainsInMotion.proxy.seatGUI(player,transport);
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
});
}
//train specific
if (transport instanceof EntityTrainCore) {
if (player.capabilities.isCreativeMode) {
Expand Down Expand Up @@ -397,28 +417,31 @@ private void renderTrainInventory(Minecraft mc){
* todo: set this up just to render the passenger icons and empty seats above the player inventory
*/
private void renderPassengerInventory(Minecraft mc){

mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory);
GL11.glDisable(GL11.GL_LIGHTING);
int rows=0;
//draw the character backgrounds.
mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory);
//make a loop that will make a new row every 5 items
for (int i=0;i<transport.getRiderOffsets().length; i++) {
if (i/(rows+1) >=5*(rows+1)){
rows++;
}
ClientUtil.drawTexturedRect(guiLeft + 7 + (30*(i-(rows * 5))), guiTop + 30+(30*rows), 54, 51, 27, 27, 20, 20);
ClientUtil.drawTexturedRect(guiLeft + 106 + (30*(i-(rows * 5))), guiTop + 30+(30*rows), 54, 51, 27, 27, 20, 20);
}
//make a new loop that does the same as above but binds the character's face rather than the inventory slot background.
for (int i=0;i<transport.getRiderOffsets().length; i++) {
if (i/(rows+1) >=5*(rows+1)){
rows++;
}
if (i>0 && transport.seats.get(i).getPassenger() instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.seats.get(i).getPassenger()).getLocationSkin());
ClientUtil.drawTexturedRect(guiLeft + 10 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 22, 22, 36, 56);
if (i==0 && transport.riddenByEntity instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.riddenByEntity).getLocationSkin());
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56);
} else if (i>0 && transport.seats.get(i-1).riddenByEntity instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.seats.get(i-1).riddenByEntity).getLocationSkin());
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56);
}
}

GL11.glEnable(GL11.GL_LIGHTING);
}

/**
Expand Down
Loading

0 comments on commit 20241b4

Please sign in to comment.