generated from calmilamsy/stationapi-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from telvarost/75-stay-in-vehicle-when-logging…
…-out-and-back-in ISSUE-75 - Fix finding saved vehicle on login
- Loading branch information
Showing
5 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/github/telvarost/annoyancefix/mixin/LevelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.github.telvarost.annoyancefix.mixin; | ||
|
||
import com.github.telvarost.annoyancefix.Config; | ||
import com.github.telvarost.annoyancefix.ModHelper; | ||
import net.minecraft.entity.EntityBase; | ||
import net.minecraft.entity.player.PlayerBase; | ||
import net.minecraft.level.Level; | ||
import net.modificationstation.stationapi.api.entity.player.PlayerHelper; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(Level.class) | ||
public class LevelMixin { | ||
|
||
@Shadow public boolean isServerSide; | ||
|
||
@Shadow public List entities; | ||
|
||
@Inject( | ||
method = "spawnEntity", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/level/Level;method_219(Lnet/minecraft/entity/EntityBase;)V" | ||
) | ||
) | ||
public void spawnEntity(EntityBase arg, CallbackInfoReturnable<Boolean> cir) { | ||
if ( (Config.config.boatLogoutLoginFixesEnabled) | ||
&& (ModHelper.ModHelperFields.isVehicleSaved) | ||
&& (!this.isServerSide) | ||
) { | ||
/** - Find saved vehicle if on single player */ | ||
for (int entityIndex = 0; entityIndex < this.entities.size(); entityIndex++) { | ||
EntityBase entityToCheck = (EntityBase) this.entities.get(entityIndex); | ||
|
||
if ( (entityToCheck.getClass().equals(ModHelper.ModHelperFields.savedVehicleClass)) | ||
&& (1 > Math.abs(entityToCheck.x - ModHelper.ModHelperFields.savedVehicleX)) | ||
&& (1 > Math.abs(entityToCheck.y - ModHelper.ModHelperFields.savedVehicleY)) | ||
&& (1 > Math.abs(entityToCheck.z - ModHelper.ModHelperFields.savedVehicleZ)) | ||
) { | ||
PlayerBase player = PlayerHelper.getPlayerFromGame(); | ||
if (null != player) { | ||
player.startRiding(entityToCheck); | ||
} | ||
ModHelper.ModHelperFields.isVehicleSaved = false; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters