Fix respawning on cloud blocks

This commit is contained in:
Sollace 2024-04-26 16:40:43 +01:00
parent dcaaca149b
commit 68025e4642
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
8 changed files with 28 additions and 6 deletions

View file

@ -31,7 +31,7 @@ public interface EquineContext {
static EquineContext of(ShapeContext context) { static EquineContext of(ShapeContext context) {
if (context == ShapeContext.absent()) { if (context == ShapeContext.absent()) {
return InteractionManager.getInstance().getClientPony().map(EquineContext.class::cast).orElse(ABSENT); return InteractionManager.getInstance().getEquineContext();
} }
EquineContext result = context instanceof Container c ? c.get() : ABSENT; EquineContext result = context instanceof Container c ? c.get() : ABSENT;
return result == null ? ABSENT : result; return result == null ? ABSENT : result;

View file

@ -37,6 +37,8 @@ public class InteractionManager {
@Nullable @Nullable
private SyncedConfig config; private SyncedConfig config;
private EquineContext equineContext = EquineContext.ABSENT;
public static InteractionManager getInstance() { public static InteractionManager getInstance() {
return INSTANCE; return INSTANCE;
} }
@ -106,6 +108,14 @@ public class InteractionManager {
} }
public void setEquineContext(EquineContext context) {
equineContext = context;
}
public EquineContext getEquineContext() {
return getClientPony().map(EquineContext.class::cast).orElse(equineContext);
}
public Optional<Pony> getClientPony() { public Optional<Pony> getClientPony() {
return Optional.empty(); return Optional.empty();
} }

View file

@ -24,7 +24,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
private final CloudBlock baseBlock; private final CloudBlock baseBlock;
public CloudBedBlock(String base, BlockState baseState, Settings settings) { public CloudBedBlock(String base, BlockState baseState, Settings settings) {
super(base, settings); super(base, settings.dynamicBounds());
this.baseState = baseState; this.baseState = baseState;
this.baseBlock = (CloudBlock)baseState.getBlock(); this.baseBlock = (CloudBlock)baseState.getBlock();
} }

View file

@ -30,7 +30,7 @@ public class CloudBlock extends Block implements CloudLike {
protected final boolean meltable; protected final boolean meltable;
public CloudBlock(Settings settings, boolean meltable) { public CloudBlock(Settings settings, boolean meltable) {
super((meltable ? settings.ticksRandomly() : settings).nonOpaque()); super((meltable ? settings.ticksRandomly() : settings).nonOpaque().dynamicBounds());
this.meltable = meltable; this.meltable = meltable;
} }

View file

@ -77,7 +77,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
}; };
public CloudChestBlock(Settings settings, BlockState baseState) { public CloudChestBlock(Settings settings, BlockState baseState) {
super(settings, () -> UBlockEntities.CLOUD_CHEST); super(settings.dynamicBounds(), () -> UBlockEntities.CLOUD_CHEST);
this.baseState = baseState; this.baseState = baseState;
this.baseBlock = (CloudBlock)baseState.getBlock(); this.baseBlock = (CloudBlock)baseState.getBlock();
} }

View file

@ -26,7 +26,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
private final CloudBlock baseBlock; private final CloudBlock baseBlock;
public CloudDoorBlock(Settings settings, BlockState baseState, BlockSetType blockSet) { public CloudDoorBlock(Settings settings, BlockState baseState, BlockSetType blockSet) {
super(settings, blockSet); super(settings.dynamicBounds(), blockSet);
this.baseState = baseState; this.baseState = baseState;
this.baseBlock = (CloudBlock)baseState.getBlock(); this.baseBlock = (CloudBlock)baseState.getBlock();
} }

View file

@ -21,7 +21,7 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
private final CloudBlock baseBlock; private final CloudBlock baseBlock;
public CloudStairsBlock(BlockState baseState, Settings settings) { public CloudStairsBlock(BlockState baseState, Settings settings) {
super(baseState, settings); super(baseState, settings.dynamicBounds());
this.baseBlock = (CloudBlock)baseState.getBlock(); this.baseBlock = (CloudBlock)baseState.getBlock();
} }

View file

@ -5,7 +5,10 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.EquineContext;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -34,4 +37,13 @@ abstract class MixinPlayerManager {
} }
} }
@Inject(method = "respawnPlayer", at = @At("HEAD"))
private void beforeRespawnPlayer(ServerPlayerEntity player, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> info) {
InteractionManager.getInstance().setEquineContext(EquineContext.of(player));
}
@Inject(method = "respawnPlayer", at = @At("RETURN"))
private void afterRespawnPlayer(ServerPlayerEntity player, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> info) {
InteractionManager.getInstance().setEquineContext(EquineContext.ABSENT);
}
} }