Skip to content

Commit

Permalink
Send a message when the player resets their spawn point with bedSpawn…
Browse files Browse the repository at this point in the history
…Fix enabled

Also refactor accessor mixins into separate packages

Signed-off-by: unilock <unilock@fennet.rentals>
  • Loading branch information
unilock committed Mar 23, 2024
1 parent 4b60b02 commit 366de47
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/main/java/cc/unilock/legacyfixes/mixin/BlockBedMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cc.unilock.legacyfixes.mixin;

import cc.unilock.legacyfixes.LegacyFixesConfig;
import cc.unilock.legacyfixes.mixin.accessor.EntityPlayerAccessor;
import net.minecraft.block.BlockBed;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -14,6 +16,12 @@
public class BlockBedMixin {
@Inject(method = "Lnet/minecraft/block/BlockBed;onBlockActivated(Lnet/minecraft/world/World;IIILnet/minecraft/entity/player/EntityPlayer;IFFF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;sleepInBedAt(III)Lnet/minecraft/entity/player/EntityPlayer$EnumStatus;"))
private void legacyfixes$onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ, CallbackInfoReturnable<Boolean> cir) {
if (LegacyFixesConfig.bedSpawnFix) player.setSpawnChunk(new ChunkCoordinates(x, y, z), false);
if (LegacyFixesConfig.bedSpawnFix) {
ChunkCoordinates spawnChunk = new ChunkCoordinates(x, y, z);
if (!spawnChunk.equals(((EntityPlayerAccessor) player).getSpawnChunk())) {
player.setSpawnChunk(spawnChunk, false);
player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.setSpawnChunk"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cc.unilock.legacyfixes.mixin.accessor;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChunkCoordinates;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(EntityPlayer.class)
public interface EntityPlayerAccessor {
@Accessor
ChunkCoordinates getSpawnChunk();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unilock.legacyfixes.mixin.client;
package cc.unilock.legacyfixes.mixin.client.accessor;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagList;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/unilock/legacyfixes/util/NBTUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.unilock.legacyfixes.util;

import cc.unilock.legacyfixes.mixin.client.NBTTagListAccessor;
import cc.unilock.legacyfixes.mixin.client.accessor.NBTTagListAccessor;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/legacyfixes/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tile.bed.setSpawnChunk=Respawn point set
5 changes: 3 additions & 2 deletions src/main/resources/mixins.legacyfixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"BlockFarmlandMixin",
"EntityLivingBaseMixin",
"EntityPlayerMixin",
"ItemInWorldManagerMixin"
"ItemInWorldManagerMixin",
"accessor.EntityPlayerAccessor"
],
"client": [
"client.FontRendererMixin",
"client.GuiNewChatMixin",
"client.GuiTextFieldMixin",
"client.ItemEnchantedBookMixin",
"client.ItemStackMixin",
"client.NBTTagListAccessor"
"client.accessor.NBTTagListAccessor"
],
"server": []
}

0 comments on commit 366de47

Please sign in to comment.