-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b58269c
commit 5cb025a
Showing
9 changed files
with
202 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.quickVillagerLevelUp; | ||
|
||
import club.mcams.carpet.AmsServerSettings; | ||
|
||
import net.minecraft.entity.passive.VillagerEntity; | ||
|
||
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(VillagerEntity.class) | ||
public abstract class VillagerEntityMixin implements VillagerEntityInvoker{ | ||
@Inject(method = "getExperience", at = @At("HEAD")) | ||
private void quickLevelUp(CallbackInfoReturnable<Integer> cir) { | ||
if (AmsServerSettings.quickVillagerLevelUp && this.invokerGetVillagerData().getLevel() < 5) { | ||
this.invokerLevelUp(); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/club/mcams/carpet/mixin/rule/renewableNetherScrap/EntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.renewableNetherScrap; | ||
|
||
import club.mcams.carpet.AmsServerSettings; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.ItemEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.entity.mob.ZombifiedPiglinEntity; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Entity.class) | ||
public abstract class EntityMixin { | ||
|
||
@Shadow | ||
@Nullable | ||
public abstract ItemEntity dropStack(ItemStack stack, float yOffset); | ||
|
||
@Unique | ||
private boolean isFirstDrop = true; | ||
|
||
@Inject(method = "dropStack(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/entity/ItemEntity;", at = @At("TAIL"), cancellable = true) | ||
private void dropNetheriteScrap(CallbackInfoReturnable<ItemEntity> cir) { | ||
if (AmsServerSettings.renewableNetheriteScrap != 0.0D && isFirstDrop) { | ||
Entity entity = (Entity) (Object) this; | ||
if (entity instanceof ZombifiedPiglinEntity && !((ZombifiedPiglinEntity) entity).isBaby()) { | ||
double random = Math.random(); | ||
double rate = AmsServerSettings.renewableNetheriteScrap; | ||
if (random < rate) { | ||
ItemStack netherScrapStack = new ItemStack(Items.NETHERITE_SCRAP); | ||
ItemEntity netherScrapItemEntity = this.dropStack(netherScrapStack, 1.1F); | ||
isFirstDrop = false; | ||
cir.setReturnValue(netherScrapItemEntity); | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/club/mcams/carpet/validators/rule/renewableNetherScrap/DropRateValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.validators.rule.renewableNetherScrap; | ||
|
||
import carpet.settings.ParsedRule; | ||
import carpet.settings.Validator; | ||
|
||
import club.mcams.carpet.translations.Translator; | ||
|
||
import net.minecraft.server.command.ServerCommandSource; | ||
|
||
public class DropRateValidator extends Validator<Double> { | ||
private static final Translator translator = new Translator("validator.renewableNetherScrap"); | ||
|
||
@Override | ||
public Double validate(ServerCommandSource serverCommandSource, ParsedRule<Double> parsedRule, Double aDouble, String s) { | ||
return aDouble >= 0.0D && aDouble <= 1.0D ? aDouble : null; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return translator.tr("value_range").getString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters