Skip to content

Commit

Permalink
Fix crash when fake players get summoned clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 3, 2021
1 parent fc065ee commit 8c1cf9f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 0.3.2
------------------------------------------------------
**Fixes**
- Fixed a crash when a mod tried to create a fake player clientside

------------------------------------------------------
Version 0.3.1
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with Baritone. If not, see <https://www.gnu.org/licenses/>.
#
mod_name = Automatone
mod_version = 0.3.1
mod_version = 0.3.2
maven_group = io.github.ladysnake

fabric_version = 0.32.0+1.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -49,6 +50,7 @@
import org.jetbrains.annotations.Nullable;

import javax.annotation.CheckForNull;
import java.util.UUID;

public class FakeClientPlayerEntity extends OtherClientPlayerEntity implements AutomatoneFakePlayer {
protected PlayerListEntry listEntry;
Expand All @@ -59,6 +61,10 @@ public static <P extends PlayerEntity & AutomatoneFakePlayer> P createClientFake
return factory.create(playerType, world, profile);
}

public FakeClientPlayerEntity(EntityType<?> type, ClientWorld clientWorld) {
this(type, clientWorld, new GameProfile(UUID.randomUUID(), I18n.translate(type.getTranslationKey())));
}

public FakeClientPlayerEntity(EntityType<?> type, ClientWorld clientWorld, GameProfile gameProfile) {
super(clientWorld, gameProfile);
((IEntityAccessor)this).automatone$setType(type);
Expand Down
3 changes: 3 additions & 0 deletions src/launch/resources/assets/automatone/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entity.automatone.fake_player": "Fake Player"
}
6 changes: 5 additions & 1 deletion src/main/java/baritone/Automatone.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

package baritone;

import baritone.api.fakeplayer.FakeClientPlayerEntity;
import baritone.api.fakeplayer.FakeServerPlayerEntity;
import baritone.command.defaults.DefaultCommands;
import baritone.command.manager.BaritoneArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.command.argument.ArgumentTypes;
import net.minecraft.command.argument.serialize.ConstantArgumentSerializer;
import net.minecraft.entity.EntityDimensions;
Expand Down Expand Up @@ -59,7 +61,9 @@ public final class Automatone implements ModInitializer {

public static final EntityType<PlayerEntity> FAKE_PLAYER = FabricEntityTypeBuilder.<PlayerEntity>createLiving()
.spawnGroup(SpawnGroup.MISC)
.entityFactory((type, world) -> new FakeServerPlayerEntity(type, (ServerWorld) world))
.entityFactory((type, world) -> world.isClient
? new FakeClientPlayerEntity(type, (ClientWorld) world)
: new FakeServerPlayerEntity(type, (ServerWorld) world))
.defaultAttributes(PlayerEntity::createPlayerAttributes)
.dimensions(EntityDimensions.changing(EntityType.PLAYER.getWidth(), EntityType.PLAYER.getHeight()))
.trackRangeBlocks(64)
Expand Down

0 comments on commit 8c1cf9f

Please sign in to comment.