Added Telekinesis and reworked Replenish
This commit is contained in:
@@ -69,6 +69,14 @@ Code inspired by Inferis!
|
||||
- Zoom step value
|
||||
- Scroll to zoom further
|
||||
|
||||
# Current Update
|
||||
|
||||
## Server Side
|
||||
- [x] Telekinesis
|
||||
- [x] Configurable for Entity & Block seperately
|
||||
- [x] Replenish Rework
|
||||
|
||||
|
||||
# To-do
|
||||
|
||||
## General
|
||||
@@ -78,7 +86,6 @@ Code inspired by Inferis!
|
||||
## Client side
|
||||
|
||||
## Server Side
|
||||
- Telekinesis
|
||||
|
||||
Other than that no more features!
|
||||
Be sure to give your idea by [opening an issue](https://git.hak.wtf/hkuijlman/SurvivalFabric/issues/new) with the label Feature Request
|
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public class Config {
|
||||
|
||||
public String configVersion = "1.1";
|
||||
public String configVersion = "1.2";
|
||||
|
||||
public boolean joinMessageEnabled = true;
|
||||
public String joinMessage = "§8[§a+§8] §7%s";
|
||||
@@ -30,7 +30,7 @@ public class Config {
|
||||
public String sharedEnderChestName = "Ender Chest";
|
||||
public int sharedEnderChestRows = 6;
|
||||
public boolean sharedEnderChestLimitedAccess = false;
|
||||
public List<String> sharedEnderChestNames = Lists.newArrayList("AlwaysHAK");
|
||||
public List<String> sharedEnderChestNames = Lists.newArrayList("AlwaysHAK", "Oazzies", "LunaticFox");
|
||||
|
||||
public String inSlimeChunkMessage = "§aYou're currently in a slime chunk";
|
||||
public String notInSlimeChunkMessage = "§cYou're currently not in a slime chunk";
|
||||
@@ -43,6 +43,9 @@ public class Config {
|
||||
|
||||
public boolean replenishEnabled = false;
|
||||
|
||||
public boolean blockTelekinesisEnabled = true;
|
||||
public boolean entityTelekinesisEnabled = true;
|
||||
|
||||
public ScreenHandlerType<GenericContainerScreenHandler> screenHandlerType() {
|
||||
return switch (sharedEnderChestRows) {
|
||||
case 1 -> ScreenHandlerType.GENERIC_9X1;
|
||||
|
@@ -0,0 +1,75 @@
|
||||
package wtf.hak.survivalfabric.features;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||
import wtf.hak.survivalfabric.mixin.ExperienceOrbEntityInvoker;
|
||||
import wtf.hak.survivalfabric.utils.Scheduler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TelekinesisHandler {
|
||||
|
||||
public static final ThreadLocal<ServerPlayerEntity> blockThreadLocal = new ThreadLocal<>();
|
||||
public static final ThreadLocal<DamageSource> entityThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static List<ItemStack> handleBlock(List<ItemStack> originalItems, BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
if (entity instanceof ServerPlayerEntity player && ConfigManager.getConfig().blockTelekinesisEnabled) {
|
||||
originalItems.removeIf(player.getInventory()::insertStack);
|
||||
blockThreadLocal.set(player);
|
||||
Scheduler.get().scheduleTask(blockThreadLocal::remove);
|
||||
}
|
||||
return originalItems;
|
||||
}
|
||||
|
||||
public static int handleBlockExp(int original) {
|
||||
if(blockThreadLocal.get() != null && ConfigManager.getConfig().blockTelekinesisEnabled) {
|
||||
ServerPlayerEntity player = blockThreadLocal.get();
|
||||
ExperienceOrbEntity fakeExperienceOrb = new ExperienceOrbEntity(player.getWorld(), 0.0, 0.0, 0.0, original);
|
||||
((ExperienceOrbEntityInvoker) fakeExperienceOrb).invokeRepairPlayerGears(player, original);
|
||||
player.addExperience(fakeExperienceOrb.getValue());
|
||||
return 0;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
public static void registerLoot(DamageSource source) {
|
||||
if(source.getAttacker() instanceof ServerPlayerEntity && ConfigManager.getConfig().entityTelekinesisEnabled) {
|
||||
entityThreadLocal.set(source);
|
||||
Scheduler.get().scheduleTask(entityThreadLocal::remove);
|
||||
}
|
||||
}
|
||||
|
||||
public static Consumer<ItemStack> handleLoot(Consumer<ItemStack> consumer, LivingEntity entity) {
|
||||
if (entityThreadLocal.get() != null) {
|
||||
return (item) -> {
|
||||
if (!((ServerPlayerEntity) entityThreadLocal.get().getAttacker()).getInventory().insertStack(item)) {
|
||||
entity.dropStack((ServerWorld) entity.getWorld(), item);
|
||||
}
|
||||
};
|
||||
} else
|
||||
return consumer;
|
||||
}
|
||||
|
||||
public static int handleEntityExp(int original) {
|
||||
if(entityThreadLocal.get() != null) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) entityThreadLocal.get().getAttacker();
|
||||
ExperienceOrbEntity fakeExperienceOrb = new ExperienceOrbEntity(player.getWorld(), 0.0, 0.0, 0.0, original);
|
||||
((ExperienceOrbEntityInvoker) fakeExperienceOrb).invokeRepairPlayerGears(player, original);
|
||||
player.addExperience(fakeExperienceOrb.getValue());
|
||||
return 0;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -3,33 +3,22 @@ package wtf.hak.survivalfabric.mixin;
|
||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CropBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.HoeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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;
|
||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||
import wtf.hak.survivalfabric.features.TelekinesisHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.block.Block.getDroppedStacks;
|
||||
@@ -45,41 +34,32 @@ public abstract class BlockMixin {
|
||||
)
|
||||
)
|
||||
private static List<ItemStack> modifyDrops(List<ItemStack> original, BlockState state, World world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) {
|
||||
|
||||
if(entity instanceof ServerPlayerEntity player) {
|
||||
original.removeIf(player.getInventory()::insertStack);
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
@Inject(method = "onBreak", at = @At("HEAD"), cancellable = true)
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir) {
|
||||
if (world.isClient()) return;
|
||||
|
||||
if (state.getBlock() instanceof CropBlock && ConfigManager.getConfig().replenishEnabled) {
|
||||
ItemStack mainHand = player.getStackInHand(Hand.MAIN_HAND);
|
||||
if (mainHand.getItem() instanceof HoeItem) {
|
||||
Item seedItem = state.getBlock().asItem();
|
||||
Block seedBlock = state.getBlock();
|
||||
List<ItemStack> drops = getDroppedStacks(state, (ServerWorld) world, pos, null, player, mainHand);
|
||||
if (removeIfAvailable(drops, seedItem)) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
for (ItemStack drop : drops) {
|
||||
Block.dropStack(world, pos, drop);
|
||||
}
|
||||
player.incrementStat(Stats.USED.getOrCreateStat(seedItem));
|
||||
mainHand.damage(1, player, EquipmentSlot.MAINHAND);
|
||||
if (state.getBlock() instanceof CropBlock && ConfigManager.getConfig().replenishEnabled) {
|
||||
ItemStack mainHand = player.getStackInHand(Hand.MAIN_HAND);
|
||||
if (mainHand.getItem() instanceof HoeItem) {
|
||||
Item seedItem = state.getBlock().asItem();
|
||||
Block seedBlock = state.getBlock();
|
||||
if (removeIfAvailable(original, seedItem)) {
|
||||
player.getServer().executeSync(() -> world.setBlockState(pos, seedBlock.getDefaultState()));
|
||||
}
|
||||
world.getServer().executeSync(() -> world.setBlockState(pos, seedBlock.getDefaultState()));
|
||||
cir.setReturnValue(Blocks.AIR.getDefaultState());
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
return TelekinesisHandler.handleBlock(original, state, world, pos, entity);
|
||||
}
|
||||
|
||||
private boolean removeIfAvailable(List<ItemStack> drops, Item item) {
|
||||
@ModifyExpressionValue(
|
||||
method = "dropExperienceWhenMined",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/enchantment/EnchantmentHelper;getBlockExperience(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/item/ItemStack;I)I")
|
||||
)
|
||||
private int modifyExp(int original) {
|
||||
return TelekinesisHandler.handleBlockExp(original);
|
||||
}
|
||||
|
||||
private static boolean removeIfAvailable(List<ItemStack> drops, Item item) {
|
||||
for (ItemStack drop : drops) {
|
||||
if (drop.getItem() == item) {
|
||||
drop.decrement(1);
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package wtf.hak.survivalfabric.mixin;
|
||||
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(ExperienceOrbEntity.class)
|
||||
public interface ExperienceOrbEntityInvoker {
|
||||
|
||||
@Invoker("repairPlayerGears")
|
||||
int invokeRepairPlayerGears(
|
||||
ServerPlayerEntity player,
|
||||
int amount
|
||||
);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package wtf.hak.survivalfabric.mixin;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.LootTable;
|
||||
import net.minecraft.loot.context.LootWorldContext;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.World;
|
||||
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.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import wtf.hak.survivalfabric.features.TelekinesisHandler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class LivingEntityMixin {
|
||||
|
||||
@Inject(method = "drop", at = @At("HEAD"))
|
||||
private void drop(ServerWorld world, DamageSource damageSource, CallbackInfo ci) {
|
||||
if(damageSource.getAttacker() instanceof ServerPlayerEntity) {
|
||||
TelekinesisHandler.registerLoot(damageSource);
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArg(
|
||||
method = "dropLoot",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/loot/LootTable;generateLoot(Lnet/minecraft/loot/context/LootWorldContext;JLjava/util/function/Consumer;)V"
|
||||
),
|
||||
index = 2
|
||||
)
|
||||
private Consumer<ItemStack> modifyLootConsumer(Consumer<ItemStack> lootConsumer) {
|
||||
return TelekinesisHandler.handleLoot(lootConsumer, (LivingEntity) (Object) this);
|
||||
}
|
||||
|
||||
@ModifyArg(method = "dropExperience",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/ExperienceOrbEntity;spawn(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/Vec3d;I)V"),
|
||||
index = 2)
|
||||
private int modifyExp(int originalExperience) {
|
||||
return TelekinesisHandler.handleEntityExp(originalExperience);
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"BlockMixin",
|
||||
"ExperienceOrbEntityInvoker",
|
||||
"LivingEntityMixin",
|
||||
"PlayerManagerMixin",
|
||||
"ServerPlayerEntityMixin",
|
||||
"ServerPlayNetworkHandlerMixin",
|
||||
|
Reference in New Issue
Block a user