Skip to content

Commit

Permalink
Added 1.17, 1.18 and 1.19 Stonecutter's versioned comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RLLD576 committed Jul 21, 2024
1 parent 17e1117 commit 42444f0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/rober/robercarpet/RoberCarpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class RoberCarpet implements ModInitializer, CarpetExtension {

@Override
public void onInitialize() {
FarmableClayBehavior.init();
//? if <1.19
/*FarmableClayBehavior.init();*/
RoberCarpet extension = new RoberCarpet();
CarpetServer.manageExtension(extension);
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@

@Mixin(FallingBlockEntity.class)
public abstract class FallingBlockMixin {
@Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 1))
//? if =1.17 {
/*@Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 1))
*///?} else {
@Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 0))
//?}
private boolean FallingBlockBehaviorMixin(BlockState blockHitResult, Block arg){
FallingBlockEntity self = (FallingBlockEntity) (Object) this;
BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
//? <1.19 {
/*BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
*///?} else {
BlockPos pos = new BlockPos((int) self.getPos().getX(), (int) Math.ceil(self.getPos().getY()), (int) self.getPos().getZ()).down();
//?}
Block underneath = self.world.getBlockState(pos).getBlock();
return blockHitResult.isOf(arg)||(underneath==Blocks.AIR&& RoberCarpetSettings.OldFallingBehavior);
}
@Redirect(method="tick()V",at=@At(value="INVOKE",target = "Lnet/minecraft/util/math/Vec3d;multiply(DDD)Lnet/minecraft/util/math/Vec3d;",ordinal = 0))
private Vec3d FrictionMixin(Vec3d vec,double x,double y,double z){
FallingBlockEntity self = (FallingBlockEntity) (Object) this;
BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
//? <1.19 {
/*BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
*///?} else {
BlockPos pos = new BlockPos((int) self.getPos().getX(), (int) Math.ceil(self.getPos().getY()), (int) self.getPos().getZ()).down();
//?}
Block underneath = self.world.getBlockState(pos).getBlock();
return underneath==Blocks.AIR&&RoberCarpetSettings.FallingBlockNoFrictionWithWalls?vec:vec.multiply(x,y,z);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.rober.robercarpet.mixin;

import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.rober.robercarpet.RoberCarpetSettings;
import org.jetbrains.annotations.Nullable;
Expand All @@ -14,63 +12,52 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

//? if <1.19.4 {
/*import net.minecraft.text.LiteralText;
import net.minecraft.util.registry.RegistryKey;*/
//?} else {
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.Text;
//?}

@Mixin(value = ServerPlayerEntity.class, priority = 100)
public abstract class SleepInBedSetRespawnMixin {
//@Redirect(method = "trySleep", at = @At(value = "INVOKE",
//target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSpawnPoint(Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/util/math/BlockPos;FZZ)V"))
@Unique
private void setSpawnPointRedirect(ServerPlayerEntity player, RegistryKey<World> dimension, @Nullable BlockPos pos, float angle, boolean spawnPointSet, boolean sendMessage){
switch(RoberCarpetSettings.SleepInBedSetRespawn){
case "always":
player.setSpawnPoint(dimension, pos, angle, spawnPointSet, sendMessage);
if(RoberCarpetSettings.SendSetRespawnFeedback)player.sendMessage(new LiteralText("You have set your respawn point"),true);
break;
case "sneaking":
case "no-sneaking":
boolean sneaking = player.isSneaking();
if(sneaking && (Objects.equals(RoberCarpetSettings.SleepInBedSetRespawn, "sneaking"))) {
player.setSpawnPoint(dimension, pos, angle, spawnPointSet, sendMessage);
player.sendMessage(new LiteralText("You have set your respawn point"),false);
}
else{
player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false);
}
break;
case "never":
player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false);
}
}
@Inject(method="setSpawnPoint", at=@At(value="HEAD"), cancellable = true)
private void setSpawnPointInjector(RegistryKey<World> dimension, @Nullable BlockPos pos, float angle, boolean spawnPointSet, boolean sendMessage, CallbackInfo ci){
private void setSpawnPointInjector(RegistryKey<World> dimension, BlockPos pos, float angle, boolean forced, boolean sendMessage, CallbackInfo ci){
ServerPlayerEntity player = (ServerPlayerEntity) ((Object) this);
switch(RoberCarpetSettings.SleepInBedSetRespawn){
switch(RoberCarpetSettings.SleepInBedSetsRespawn){
case "always":
if(RoberCarpetSettings.SendSetRespawnFeedback)player.sendMessage(new LiteralText("You have set your respawn point"),true);
if(RoberCarpetSettings.SendSetRespawnFeedback)send("You have set your respawn point",player);
return;
case "sneaking":
if(player.isSneaking()){
player.sendMessage(new LiteralText("You have set your respawn point"),false);
send("You have set your respawn point",player);
return;
}else{
player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false);
send("You have slept without setting your spawn point",player);
ci.cancel();
}
break;
case "no-sneaking":
if(!player.isSneaking()){
player.sendMessage(new LiteralText("You have set your respawn point"),false);
send("You have set your respawn point",player);
return;
}else{
player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false);
send("You have slept without setting your spawn point",player);
ci.cancel();
}
break;
case "never":
player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false);
send("You have slept without setting your spawn point",player);
ci.cancel();
}
}
private static void send(String mes, ServerPlayerEntity player){
//? if <1.19 {
/*player.sendMessage(new LiteralText(mes),false);*/
//?} else
player.sendMessage(Text.of(mes),false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

@Mixin(PlayerEntity.class)
public abstract class SleepingDelayMixin {
@ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100))
//? if =1.17 {
/*@ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100))
*///?} else
@ModifyConstant(method = "canResetTimeBySleeping",constant = @Constant(intValue = 100))
public int SleepingDelayMixin(int a){
return RoberCarpetSettings.SleepingDelay;
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/net/rober/robercarpet/mixin/ThunderWarnMixin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.rober.robercarpet.mixin;

import net.minecraft.network.MessageType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.world.level.ServerWorldProperties;
import net.rober.robercarpet.RoberCarpetSettings;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -12,18 +11,27 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//? <1.19.4 {
/*import net.minecraft.network.MessageType;
import net.minecraft.text.LiteralText;
*///?}

import java.util.function.BooleanSupplier;

@Mixin(ServerWorld.class)
public abstract class ThunderWarnMixin {
@Shadow protected ServerWorldProperties worldProperties;
@Shadow
private ServerWorldProperties worldProperties;
@Inject(method = "tick",at=@At("TAIL"))
private void tickMixin(BooleanSupplier shouldKeepTicking,CallbackInfo ci){
if(RoberCarpetSettings.ThunderWarn!=-1) {
ServerWorld server = (ServerWorld) (Object) this;
if((willBeThunderstorm(RoberCarpetSettings.ThunderWarn,worldProperties))){
for (ServerPlayerEntity player : server.getPlayers()){
player.sendMessage(new LiteralText("A storm will begin in "+RoberCarpetSettings.ThunderWarn/60+" minutes"), MessageType.CHAT,player.getUuid());
//? >=1.19.4 {
player.sendMessage(Text.of("A storm will begin in " + RoberCarpetSettings.ThunderWarn / 1200 + " minutes"), false);
//?} else
/*player.sendMessage(new LiteralText("A storm will begin in "+RoberCarpetSettings.ThunderWarn/60+" minutes"), MessageType.CHAT,player.getUuid());*/
}
}
}
Expand Down

0 comments on commit 42444f0

Please sign in to comment.