Skip to content

Commit

Permalink
add sweetberry drops and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Jan 20, 2024
1 parent a53ef28 commit 07e7a84
Show file tree
Hide file tree
Showing 24 changed files with 317 additions and 140 deletions.
3 changes: 3 additions & 0 deletions changelogs/fabric-2.4.0-1.20.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v2.4.0-1.20.4
- add sweet berry bush drops
- update fabric loader dependency
4 changes: 2 additions & 2 deletions telekinesis-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

group = "dev.nyon"
val majorVersion = "2.3.5"
val majorVersion = "2.4.0"
val mcVersion = "1.20.4"
val supportedMcVersions = listOf("1.20.3", "1.20.4")
version = "$majorVersion-1.20.4"
Expand Down Expand Up @@ -51,7 +51,7 @@ dependencies {
officialMojangMappings()
})
implementation("org.vineflower:vineflower:1.9.3")
modImplementation("net.fabricmc:fabric-loader:0.15.3")
modImplementation("net.fabricmc:fabric-loader:0.15.6")
modImplementation("net.fabricmc:fabric-language-kotlin:1.10.17+kotlin.1.9.22")
modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.1+1.20.4")
modImplementation("com.terraformersmc:modmenu:9.0.0-pre.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ public class AbstractChestedHorseMixin {
target = "Lnet/minecraft/world/entity/animal/horse/AbstractChestedHorse;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(AbstractChestedHorse instance, ItemLike item) {
public boolean redirectEquipmentDrop(
AbstractChestedHorse instance,
ItemLike item
) {
final var attacker = instance.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> {
if (!player.addItem(item.asItem().getDefaultInstance())) instance.spawnAtLocation(item);
}
);
if (!player.addItem(item.asItem()
.getDefaultInstance())) instance.spawnAtLocation(item);
});

return !hasTelekinesis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ public class AbstractHorseMixin {
target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(AbstractHorse instance, ItemStack stack) {
public boolean redirectEquipmentDrop(
AbstractHorse instance,
ItemStack stack
) {
final var attacker = instance.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
}
);
});

return !hasTelekinesis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ public class AllayMixin {
target = "Lnet/minecraft/world/entity/animal/allay/Allay;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(Allay instance, ItemStack stack) {
public boolean redirectEquipmentDrop(
Allay instance,
ItemStack stack
) {
final var attacker = instance.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
}
);
});

return !hasTelekinesis;
}
Expand All @@ -50,21 +51,22 @@ public boolean redirectEquipmentDrop(Allay instance, ItemStack stack) {
target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V"
)
)
public void redirectInventoryDrops(List<ItemStack> instance, Consumer<ItemStack> consumer) {
public void redirectInventoryDrops(
List<ItemStack> instance,
Consumer<ItemStack> consumer
) {
final var attacker = allay.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) {
instance.forEach(consumer);
return;
}

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> instance.forEach(item -> {
if (!player.addItem(item)) consumer.accept(item);
})
);
}));

if (!hasTelekinesis) instance.forEach(consumer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@ private static void redirectDrops(
ItemStack itemStack
) {
args.<Consumer<ItemStack>>set(0, item -> {
if (!TelekinesisUtils.handleTelekinesisBlock(
TelekinesisPolicy.BlockDrops,
entity,
itemStack,
player -> {
if (!player.addItem(item)) {
Block.popResource(level, blockPos, item);
}
})
) Block.popResource(level, blockPos, item);
if (!TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.BlockDrops, entity, itemStack, player -> {
if (!player.addItem(item)) Block.popResource(level, blockPos, item);
})) Block.popResource(level, blockPos, item);
});
}

Expand All @@ -65,25 +58,37 @@ private static void redirectDrops(
cancellable = true
)
private static void manipulateDrops(
BlockState blockState, Level level, BlockPos blockPos, BlockEntity blockEntity, Entity entity, ItemStack itemStack, CallbackInfo ci
BlockState blockState,
Level level,
BlockPos blockPos,
BlockEntity blockEntity,
Entity entity,
ItemStack itemStack,
CallbackInfo ci
) {
if (!(level instanceof ServerLevel serverLevel)) return;
Block block = blockState.getBlock();
if (EnchantmentHelper.hasSilkTouch(itemStack)) return;
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops, entity, itemStack, player -> {
int expToAdd = 0;
if (block instanceof DropExperienceBlock expBlock)
expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange().sample(level.random);
if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5);
if (block instanceof SculkCatalystBlock catalystBlock)
expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange().sample(level.random);
if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock)
expToAdd = ConstantInt.of(5).sample(level.random);
if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15);
if (block instanceof InfestedBlock infestedBlock)
infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true);
PlayerUtils.addExpToPlayer(player, expToAdd);
});
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops,
entity,
itemStack,
player -> {
int expToAdd = 0;
if (block instanceof DropExperienceBlock expBlock)
expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange()
.sample(level.random);
if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5);
if (block instanceof SculkCatalystBlock catalystBlock)
expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange()
.sample(level.random);
if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock)
expToAdd = ConstantInt.of(5)
.sample(level.random);
if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15);
if (block instanceof InfestedBlock infestedBlock)
infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true);
PlayerUtils.addExpToPlayer(player, expToAdd);
});

if (hasTelekinesis) ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ public class ChestBoatMixin {
target = "Lnet/minecraft/world/entity/vehicle/ChestBoat;getDropItem()Lnet/minecraft/world/item/Item;"
)
)
private Item changeDroppedItem(Item original, DamageSource damageSource) {
private Item changeDroppedItem(
Item original,
DamageSource damageSource
) {
final var attacker = damageSource.getEntity();
if (!(attacker instanceof ServerPlayer)) return original;

AtomicReference<Item> toReturn = new AtomicReference<>(original);

TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.VehicleDrops, damageSource, player -> {
if (player.addItem(original.asItem().getDefaultInstance())) toReturn.set(ItemStack.EMPTY.getItem());
if (player.addItem(original.asItem()
.getDefaultInstance())) toReturn.set(ItemStack.EMPTY.getItem());
});

return toReturn.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public abstract class EnchantmentsMixin {
method = "register",
at = @At("RETURN")
)
private static void registerTelekinesis(String identifier, Enchantment enchantment, CallbackInfoReturnable<Enchantment> cir) {
private static void registerTelekinesis(
String identifier,
Enchantment enchantment,
CallbackInfoReturnable<Enchantment> cir
) {
if (!isTelekinesisRegistered) {
MainKt.setTelekinesis(new TelekinesisEnchantment());
isTelekinesisRegistered = true;
Registry.register(BuiltInRegistries.ENCHANTMENT, new ResourceLocation("telekinesis", "telekinesis"), MainKt.getTelekinesis());
Registry.register(BuiltInRegistries.ENCHANTMENT,
new ResourceLocation("telekinesis", "telekinesis"),
MainKt.getTelekinesis());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ public class EnderManMixin {
target = "Lnet/minecraft/world/entity/monster/EnderMan;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(EnderMan instance, ItemStack stack, DamageSource damageSource, int lootingMultiplier, boolean allowDrops) {
public boolean redirectEquipmentDrop(
EnderMan instance,
ItemStack stack,
DamageSource damageSource,
int lootingMultiplier,
boolean allowDrops
) {
final var attacker = damageSource.getEntity();
if (!(attacker instanceof ServerPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, damageSource, player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
});
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
damageSource,
player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
});

return !hasTelekinesis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ private boolean redirectFishingHookDrops(
if (!(getPlayerOwner() instanceof ServerPlayer _serverPlayer)) return true;

if (entity instanceof ExperienceOrb expOrb) {
final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.ExpDrops,
final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops,
_serverPlayer,
stack,
serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, expOrb.getValue())
);
serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, expOrb.getValue()));

return !hasTelekinesis;
}

if (entity instanceof ItemEntity itemEntity) {
final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.FishingDrops,
final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.FishingDrops,
_serverPlayer,
stack,
serverPlayer -> {
if (!serverPlayer.addItem(itemEntity.getItem())) instance.addFreshEntity(itemEntity);
}
);
});

return !hasTelekinesis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ public class InventoryMixin {
target = "Lnet/minecraft/world/entity/player/Player;drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(Player instance, ItemStack stack, boolean throwRandomly, boolean retainOwnership) {
public boolean redirectEquipmentDrop(
Player instance,
ItemStack stack,
boolean throwRandomly,
boolean retainOwnership
) {
final var attacker = instance.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
}
);
});

return !hasTelekinesis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ public abstract class LivingEntityMixin {
target = "Lnet/minecraft/world/entity/ExperienceOrb;award(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V"
)
)
public boolean redirectExp(ServerLevel world, Vec3 pos, int amount) {
public boolean redirectExp(
ServerLevel world,
Vec3 pos,
int amount
) {
final var attacker = livingEntity.getLastAttacker();
if (!(attacker instanceof ServerPlayer serverPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.ExpDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops,
serverPlayer,
serverPlayer.getMainHandItem(),
player -> PlayerUtils.addExpToPlayer(player, amount)
);
player -> PlayerUtils.addExpToPlayer(player, amount));

return !hasTelekinesis;
}
Expand All @@ -52,15 +54,17 @@ public boolean redirectExp(ServerLevel world, Vec3 pos, int amount) {
target = "Lnet/minecraft/world/level/storage/loot/LootTable;getRandomItems(Lnet/minecraft/world/level/storage/loot/LootParams;JLjava/util/function/Consumer;)V"
)
)
public void redirectCommonDrops(Args args, DamageSource damageSource, boolean bl) {
public void redirectCommonDrops(
Args args,
DamageSource damageSource,
boolean bl
) {
args.<Consumer<ItemStack>>set(2, item -> {
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(
TelekinesisPolicy.MobDrops,
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
damageSource,
player -> {
if (!player.addItem(item)) livingEntity.spawnAtLocation(item);
}
);
});

if (!hasTelekinesis) livingEntity.spawnAtLocation(item);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ public class MobMixin {
target = "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"
)
)
public boolean redirectEquipmentDrop(Mob instance, ItemStack stack, DamageSource damageSource, int lootingMultiplier, boolean allowDrops) {
public boolean redirectEquipmentDrop(
Mob instance,
ItemStack stack,
DamageSource damageSource,
int lootingMultiplier,
boolean allowDrops
) {
final var attacker = damageSource.getEntity();
if (!(attacker instanceof ServerPlayer)) return true;

boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, damageSource, player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
});
boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops,
damageSource,
player -> {
if (!player.addItem(stack)) instance.spawnAtLocation(stack);
});

return !hasTelekinesis;
}
Expand Down
Loading

0 comments on commit 07e7a84

Please sign in to comment.