Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,42 @@ WesterosCraftEssentials is a custom Fabric mod that handles various requirements


## Features
A /ptime command to allow players to set their own time without affecting the server's time

A /pweather command to allow players to set their own weather without affecting the server's weather

A registry that tracks the opening and closing of doors, gates and trapdoors. When a guest opens or closes a door, after some time, it is reset to it's original condition

A large array of mixins to prevent randomTick events:

| Config | Default | Notes |
|---------------------------|---------|----------------------------------------------------------------------------|
| disableIceMelt | true | Disables ice melting |
| disableSnowMelt | true | Disables snow melt |
| snowLayerSurviveAny | true | Allows snow layers to be placed in places ordinarily not allowed |
| doPreventLeafDecay | true | Prevents leaf decay |
| disableCropGrowth | true | Prevents crop growth |
| cropSurviveAny | true | Allows crops to be placed in places ordinarily not allowed |
| disableBambooSpread | true | Prevents bamboo spread |
| bambooSurviveAny | true | Allows bamboo to be placed in places ordinarily not allowed |
| disableGrassSpread | true | Prevents grass spread |
| disableFluidTicking | true | Prevents water and lava to spread normally |
| blockWitherSpawn | true | Prevents wither spawning |
| disableMushroomGrowFade | true | Prevents mushroom growth |
| mushroomSurviveAny | true | Allows mushrooms to be placed in places ordinarily not allowed |
| forceAdventureMode | true | Enforces adventure mode on dimension changes |
| disableCactusGrowth | true | Prevents Cactus growth |
| cactusSurviveAny | true | Allows cactus to be placed in places ordinarily not allowed |
| disableFallingBlocks | true | Prevents blocks such as sand and gravel from experiencing gravity |
| disableFarmStomping | true | Prevents jumping on crops causing the farmland to dry |
| disableHunger | true | Disables hunger |
| disablePlantGrowFade | true | Prevents plant growth |
| blockHangingItemChanges | true | Prevents hanging items such as paintings and item frames from being broken |
| disableTNTExplode | true | Disables TNT explosions, |
| disableNetherWartGrowFade | true | Prevents nether wart growth |
| disableStemGrowFade | true | Prevents stem growth |
| disableSugarCaneGrowFade | true | Prevents sugar cane growth |
| sugarCaneSurviveAny | true | Allows sugar cane to be placed in places ordinarily not allowed |
| disableVineGrowFade | true | Prevents Vine growth |
| vineSurviveAny | true | Allows vines to be placed in places ordinarily not allowed |
| disableDripstoneTransfer | true | Prevents dripstone from drying mud and lava farming |
45 changes: 45 additions & 0 deletions src/main/java/westeroscraft/config/WesterosCraftConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ public class WesterosCraftConfig {
public static boolean cropSurviveAny = false;
public static boolean disableBambooSpread = false;
public static boolean bambooSurviveAny = false;
public static boolean disableCactusGrowth = false;
public static boolean cactusSurviveAny = false;
public static boolean disableFallingBlocks = false;
public static boolean disableFarmStomping = false;
public static boolean disableHunger = false;
public static boolean disablePlantGrowFade = false;
public static boolean blockHangingItemChanges = false;
public static boolean disableTNTExplode = false;
public static boolean disableNetherWartGrowFade = false;
public static boolean disableStemGrowFade = false;
public static boolean disableSugarCaneGrowFade = false;
public static boolean sugarCaneSurviveAny = false;
public static boolean disableVineGrowFade = false;
public static boolean vineSurviveAny = false;
public static boolean disableDripstoneTransfer = false;
public static boolean disableGrassSpread = false;
public static boolean disableFluidTicking = false;
public static boolean blockWitherSpawn = false;
Expand Down Expand Up @@ -59,6 +74,21 @@ private static class ConfigData {
boolean disableMushroomGrowFade = true;
boolean mushroomSurviveAny = true;
boolean forceAdventureMode = true;
boolean disableCactusGrowth = true;
boolean cactusSurviveAny = true;
boolean disableFallingBlocks = true;
boolean disableFarmStomping = true;
boolean disableHunger = true;
boolean disablePlantGrowFade = true;
boolean blockHangingItemChanges = true;
boolean disableTNTExplode = true;
boolean disableNetherWartGrowFade = true;
boolean disableStemGrowFade = true;
boolean disableSugarCaneGrowFade = true;
boolean sugarCaneSurviveAny = true;
boolean disableVineGrowFade = true;
boolean vineSurviveAny = true;
boolean disableDripstoneTransfer = true;
AutoRestoreConfig autoRestore = new AutoRestoreConfig();
}

Expand All @@ -78,6 +108,21 @@ public static void load() {
cropSurviveAny = data.cropSurviveAny;
disableBambooSpread = data.disableBambooSpread;
bambooSurviveAny = data.bambooSurviveAny;
disableCactusGrowth = data.disableCactusGrowth;
cactusSurviveAny = data.cactusSurviveAny;
disableFallingBlocks = data.disableFallingBlocks;
disableFarmStomping = data.disableFarmStomping;
disableHunger = data.disableHunger;
disablePlantGrowFade = data.disablePlantGrowFade;
blockHangingItemChanges = data.blockHangingItemChanges;
disableTNTExplode = data.disableTNTExplode;
disableNetherWartGrowFade = data.disableNetherWartGrowFade;
disableStemGrowFade = data.disableStemGrowFade;
disableSugarCaneGrowFade = data.disableSugarCaneGrowFade;
sugarCaneSurviveAny = data.sugarCaneSurviveAny;
disableVineGrowFade = data.disableVineGrowFade;
vineSurviveAny = data.vineSurviveAny;
disableDripstoneTransfer = data.disableDripstoneTransfer;
disableGrassSpread = data.disableGrassSpread;
disableFluidTicking = data.disableFluidTicking;
blockWitherSpawn = data.blockWitherSpawn;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/westeroscraft/mixin/BambooBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import westeroscraft.config.WesterosCraftConfig;

@Mixin(BambooStalkBlock.class)
public class BambooBlockMixin {
public abstract class BambooBlockMixin {
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void onTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random, CallbackInfo ci) {
if (WesterosCraftConfig.disableBambooSpread) {
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/westeroscraft/mixin/CactusBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package westeroscraft.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.CactusBlock;
import net.minecraft.world.level.block.state.BlockState;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(CactusBlock.class)
public abstract class CactusBlockMixin {
protected CactusBlockMixin() {}

@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void onTick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, RandomSource randomSource, CallbackInfo ci) {
if(WesterosCraftConfig.disableCactusGrowth) {
ci.cancel();
}
}

@Inject(method = "randomTick", at = @At("HEAD"), cancellable = true)
private void onRandomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random, CallbackInfo ci) {
if (WesterosCraftConfig.disableCactusGrowth) {
ci.cancel();
}
}

@Inject(method = "canSurvive", at = @At("HEAD"), cancellable = true)
private void onCanSurvive(BlockState state, LevelReader level, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (WesterosCraftConfig.cactusSurviveAny) {
cir.setReturnValue(true);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/westeroscraft/mixin/CropBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import westeroscraft.config.WesterosCraftConfig;

@Mixin(CropBlock.class)
public class CropBlockMixin {
public abstract class CropBlockMixin {
@Inject(method = "randomTick", at = @At("HEAD"), cancellable = true)
private void onRandomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random, CallbackInfo ci) {
if (WesterosCraftConfig.disableCropGrowth) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/westeroscraft/mixin/DoorBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import westeroscraft.restore.AutoRestoreManager;

@Mixin(DoorBlock.class)
public class DoorBlockMixin {
public abstract class DoorBlockMixin {

@Unique
private static final ThreadLocal<Boolean> originalOpenState = new ThreadLocal<>();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/westeroscraft/mixin/FallingBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package westeroscraft.mixin;

import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.world.level.block.state.BlockState;
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;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(FallingBlock.class)
public abstract class FallingBlockMixin {

protected FallingBlockMixin() {}

@Inject(method = "isFree", at = @At("HEAD"), cancellable=true)
private static void doIsFree(BlockState blockState, CallbackInfoReturnable<Boolean> ci) {
if (WesterosCraftConfig.disableFallingBlocks) {
ci.setReturnValue(Boolean.FALSE);
}
}
}
24 changes: 24 additions & 0 deletions src/main/java/westeroscraft/mixin/FarmBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package westeroscraft.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.FarmBlock;
import net.minecraft.world.level.block.state.BlockState;
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.CallbackInfo;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(FarmBlock.class)
public abstract class FarmBlockMixin {
protected FarmBlockMixin() {}

@Inject(method = "turnToDirt", at = @At("HEAD"), cancellable = true)
private static void doTurnToDirt(Entity entity, BlockState blockState, Level level, BlockPos blockPos, CallbackInfo ci) {
if (WesterosCraftConfig.disableFarmStomping) {
ci.cancel();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/westeroscraft/mixin/FenceGateBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import westeroscraft.restore.AutoRestoreManager;

@Mixin(FenceGateBlock.class)
public class FenceGateBlockMixin {
public abstract class FenceGateBlockMixin {

@Unique
private static final ThreadLocal<Boolean> originalOpenState = new ThreadLocal<>();
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/westeroscraft/mixin/FoodDataMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package westeroscraft.mixin;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(FoodData.class)
public abstract class FoodDataMixin {
@Shadow
private int foodLevel;

protected FoodDataMixin() {}

@Inject(method = "tick", at = @At("HEAD"))
private void doTick(Player player, CallbackInfo ci) {
if(WesterosCraftConfig.disableHunger) {
foodLevel = 20;
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/westeroscraft/mixin/FrostedIceBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package westeroscraft.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.FrostedIceBlock;
import net.minecraft.world.level.block.state.BlockState;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import westeroscraft.config.WesterosCraftConfig;


@Mixin(FrostedIceBlock.class)
public abstract class FrostedIceBlockMixin {
protected FrostedIceBlockMixin() {}

@Inject(method = "tick", at = @At("HEAD"), cancellable=true)
private void doTick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, RandomSource randomSource, CallbackInfo ci) {
if (WesterosCraftConfig.disableIceMelt) {
ci.cancel();
}
}

@Inject(method = "slightlyMelt", at = @At("HEAD"), cancellable=true)
private void doSlightlyMelt(BlockState bs, Level lvl, BlockPos pos, CallbackInfoReturnable<Boolean> ci) {
if (WesterosCraftConfig.disableIceMelt) {
ci.setReturnValue(Boolean.FALSE);
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/westeroscraft/mixin/GrowingPlantHeadBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package westeroscraft.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.GrowingPlantHeadBlock;
import net.minecraft.world.level.block.state.BlockState;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(GrowingPlantHeadBlock.class)
public abstract class GrowingPlantHeadBlockMixin {
protected GrowingPlantHeadBlockMixin() {}


@Inject(method = "randomTick", at = @At("HEAD"), cancellable=true)
private void doRandomTick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, RandomSource randomSource, CallbackInfo ci) {
if (WesterosCraftConfig.disablePlantGrowFade) {
ci.cancel();
}
}

@Inject(method = "isRandomlyTicking(Lnet/minecraft/world/level/block/state/BlockState;)Z", at = @At("HEAD"), cancellable=true)
private void doIsRandomlyTicking(BlockState bs, CallbackInfoReturnable<Boolean> ci) {
if (WesterosCraftConfig.disablePlantGrowFade) {
ci.setReturnValue(false);
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/westeroscraft/mixin/HangingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package westeroscraft.mixin;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.BlockAttachedEntity;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(HangingEntity.class)
public abstract class HangingEntityMixin extends BlockAttachedEntity {
protected HangingEntityMixin(EntityType<? extends HangingEntity> et, Level l) {
super(et, l);
}

@Override
public @NotNull InteractionResult interact(Player player, InteractionHand hand) {
if ((!player.isCreative()) && WesterosCraftConfig.blockHangingItemChanges) {
return InteractionResult.CONSUME;
}
return super.interact(player, hand);
}
}
2 changes: 1 addition & 1 deletion src/main/java/westeroscraft/mixin/IceBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import westeroscraft.config.WesterosCraftConfig;

@Mixin(IceBlock.class)
public class IceBlockMixin {
public abstract class IceBlockMixin {
@Inject(method = "randomTick", at = @At("HEAD"), cancellable = true)
private void onRandomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random, CallbackInfo ci) {
if (WesterosCraftConfig.disableIceMelt) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/westeroscraft/mixin/ItemFrameMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package westeroscraft.mixin;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.player.Player;
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;
import westeroscraft.config.WesterosCraftConfig;

@Mixin(ItemFrame.class)
public abstract class ItemFrameMixin {
protected ItemFrameMixin() {}


@Inject(method = "interact", at = @At("HEAD"), cancellable=true)
private void doInteract(Player player, InteractionHand hand, CallbackInfoReturnable<InteractionResult> ci) {
if ((!player.isCreative()) && WesterosCraftConfig.blockHangingItemChanges) {
ci.setReturnValue(InteractionResult.CONSUME);
}
}
@Inject(method = "hurt", at = @At("HEAD"), cancellable=true)
private void doHurt(DamageSource src, float damage, CallbackInfoReturnable<Boolean> ci) {
if ((!src.isCreativePlayer()) && WesterosCraftConfig.blockHangingItemChanges) {
ci.setReturnValue(Boolean.FALSE);
}
}
}
Loading