missing tools and motd fixed
This commit is contained in:
1 parent
bb555386d0
commit
76334f9a68
10 files changed
+106
-66
No files matched your search
@@ -51,10 +51,11 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
public static void init(MinecraftServer server) //aka constructor of this static singleton class
|
||||
{
|
||||
// no sure we really need this here, needs testing and moving to onServerLoaded
|
||||
CarpetServer.minecraft_server = server;
|
||||
//CarpetServer.minecraft_server = server;
|
||||
}
|
||||
public static void onServerLoaded(MinecraftServer server)
|
||||
{
|
||||
CarpetServer.minecraft_server = server;
|
||||
settingsManager.attachServer(server);
|
||||
extensions.forEach(e -> {
|
||||
SettingsManager sm = e.customSettingsManager();
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package carpet.fakes;
|
||||
|
||||
public interface MinecraftServer_motdInterface
|
||||
{
|
||||
String checkMOTD();
|
||||
}
|
||||
@@ -14,9 +14,10 @@ public class MinecraftDedicatedServerMixin
|
||||
// this.tickWorlds(booleanSupplier_1);
|
||||
@Inject(method = "setupServer", at = @At("TAIL"))
|
||||
private void onSetupServer(CallbackInfoReturnable<Boolean> cir) {
|
||||
//CM init - all stuff loaded from the server, just before worlds loading
|
||||
CarpetServer.onServerLoaded((MinecraftDedicatedServer) (Object) this);
|
||||
//CM start game hook
|
||||
CarpetServer.onGameStarted();
|
||||
//CM init - all stuff loaded from the server, just before worlds loading
|
||||
CarpetServer.onServerLoaded((MinecraftDedicatedServer) (Object) this);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.settings.CarpetSettings;
|
||||
import carpet.fakes.MinecraftServer_motdInterface;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
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.Redirect;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public abstract class MinecraftServer_motdMixin implements MinecraftServer_motdInterface
|
||||
{
|
||||
@Shadow private String motd;
|
||||
|
||||
@Shadow public abstract void setMotd(String string_1);
|
||||
|
||||
@Redirect(method = "run", at = @At(
|
||||
value = "FIELD",
|
||||
target = "Lnet/minecraft/server/MinecraftServer;motd:Ljava/lang/String;")
|
||||
)
|
||||
private String setCustomMotd(MinecraftServer server)
|
||||
{
|
||||
return checkMOTD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String checkMOTD()
|
||||
{
|
||||
if ("_".equals(CarpetSettings.customMOTD))
|
||||
{
|
||||
setMotd(motd);
|
||||
return motd;
|
||||
}
|
||||
else
|
||||
{
|
||||
setMotd(CarpetSettings.customMOTD);
|
||||
return CarpetSettings.customMOTD;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.settings.CarpetSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.item.PickaxeItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(PickaxeItem.class)
|
||||
public class PickaxeItem_missingToolsMixin
|
||||
{
|
||||
@Redirect(method = "getMiningSpeed", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/BlockState;getMaterial()Lnet/minecraft/block/Material;"
|
||||
))
|
||||
private Material getCustomMaterial(BlockState blockState)
|
||||
{
|
||||
Material material = blockState.getMaterial();
|
||||
if (CarpetSettings.missingTools && (material == Material.PISTON || material == Material.GLASS))
|
||||
material = Material.STONE;
|
||||
return material;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.settings.CarpetSettings;
|
||||
import net.minecraft.server.ServerMetadata;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ServerMetadata.class)
|
||||
public class ServerMetadata_motdMixin
|
||||
{
|
||||
@Inject(method = "getDescription", at = @At("HEAD"), cancellable = true)
|
||||
private void getDescriptionAlternative(CallbackInfoReturnable<Text> cir)
|
||||
{
|
||||
if (!CarpetSettings.customMOTD.equals("_"))
|
||||
{
|
||||
cir.setReturnValue(new LiteralText(CarpetSettings.customMOTD));
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.settings.CarpetSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ShearsItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ShearsItem.class)
|
||||
public class ShearsItem_missingToolsMixin
|
||||
{
|
||||
@Inject(method = "getMiningSpeed", at = @At("HEAD"), cancellable = true)
|
||||
private void getCustomMaterial(ItemStack itemStack_1, BlockState blockState_1, CallbackInfoReturnable<Float> cir)
|
||||
{
|
||||
if (CarpetSettings.missingTools && (blockState_1.getMaterial() == Material.SPONGE))
|
||||
{
|
||||
cir.setReturnValue(15.0F);
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,22 @@ import carpet.fakes.WorldInterface;
|
||||
import carpet.utils.SpawnReporter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -96,4 +101,17 @@ public class SpawnHelperMixin
|
||||
return world.spawnEntity(entity_1);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Redirect(method = "spawnEntitiesInChunk", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/player/PlayerEntity;squaredDistanceTo(DDD)D"
|
||||
))
|
||||
private static double getSqDistanceTo(PlayerEntity playerEntity, double double_1, double double_2, double double_3,
|
||||
EntityCategory entityCategory_1, World world_1, WorldChunk worldChunk_1, BlockPos blockPos_1)
|
||||
{
|
||||
double distanceTo = playerEntity.squaredDistanceTo(double_1, double_2, double_3);
|
||||
if (CarpetSettings.lagFreeSpawning && distanceTo > 16384.0D && entityCategory_1 != EntityCategory.CREATURE)
|
||||
return 0.0;
|
||||
return distanceTo;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package carpet.settings;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.fakes.MinecraftServer_motdInterface;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
@@ -209,11 +208,7 @@ public class CarpetSettings
|
||||
@Rule(desc = "Placing carpets may issue carpet commands for non-op players", category = SURVIVAL)
|
||||
public static boolean carpets = false;
|
||||
|
||||
@Rule(
|
||||
desc = "Pistons, Glass and Sponge can be broken faster with their appropriate tools",
|
||||
category = SURVIVAL,
|
||||
validate = Validator.WIP.class
|
||||
)
|
||||
@Rule(desc = "Pistons, Glass and Sponge can be broken faster with their appropriate tools", category = SURVIVAL)
|
||||
public static boolean missingTools = false;
|
||||
|
||||
@Rule(desc = "Alternative, persistent caching strategy for nether portals", category = {SURVIVAL, CREATIVE})
|
||||
@@ -287,19 +282,11 @@ public class CarpetSettings
|
||||
@Rule(desc = "One player is required on the server to cause night to pass", category = SURVIVAL)
|
||||
public static boolean onePlayerSleeping = false;
|
||||
|
||||
private static class SetMotd extends Validator<String> {
|
||||
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String string) {
|
||||
customMOTD = newValue; // accelerate a smidge
|
||||
((MinecraftServer_motdInterface) CarpetServer.minecraft_server).checkMOTD();
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
@Rule(
|
||||
desc = "Sets a different motd message on client trying to connect to the server",
|
||||
extra = "use '_' to use the startup setting from server.properties",
|
||||
options = "_",
|
||||
category = CREATIVE,
|
||||
validate = {SetMotd.class, Validator.WIP.class} // for some reason doesn't yet work
|
||||
category = CREATIVE
|
||||
)
|
||||
public static String customMOTD = "_";
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
"StructureBlockBlockEntity_fillUpdatesMixin",
|
||||
"Structure_fillUpdatesMixin",
|
||||
|
||||
"ServerMetadata_motdMixin",
|
||||
|
||||
"MinecraftServer_coreMixin",
|
||||
|
||||
"MinecraftServer_tickspeedMixin",
|
||||
@@ -23,7 +25,6 @@
|
||||
|
||||
"MobEntityMixin",
|
||||
|
||||
"MinecraftServer_motdMixin",
|
||||
"ServerPlayNetworkHandlerMixin",
|
||||
"MinecraftServer_scarpetMixin",
|
||||
"PlayerListHeaderS2CPacketMixin",
|
||||
@@ -93,6 +94,10 @@
|
||||
"PistonBlock_qcMixin",
|
||||
"DispenserBlock_qcMixin",
|
||||
|
||||
"PickaxeItem_missingToolsMixin",
|
||||
"ShearsItem_missingToolsMixin",
|
||||
|
||||
|
||||
"PistonBlock_movableTEMixin",
|
||||
"PistonBlockEntity_movableTEMixin",
|
||||
"World_movableTEMixin",
|
||||
|
||||
Reference in new issue
Block a user