Skip to content

Commit

Permalink
Merge pull request #2 from BerdinskiyBear/future-0.2.0
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
BerdinskiyBear authored Apr 5, 2020
2 parents 0aabd7a + f1ee504 commit c074f48
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 17 deletions.
19 changes: 19 additions & 0 deletions configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,24 @@ If set to `false` creative players will have same chance of enchanting a golden
By default chance of enchanting of a golden apple is about 7.6%.
For example, if you set this modifier to `6.5` 50% of all attempts will be successful.
* Default value: `1.0`
7. ##### `can_golden_apple_vanish`
This parameter determines whether golden apple can disappear if enchanting fails or not.
* Default value: `true`
8. ##### `vanishing_chance`
This parameter sets the chance of a golden apple disappearing if enchanting fails.
* Default value: `0.9`
9. ##### `can_enchanted_golden_apple_become_cursed`
This parameter allows successfully enchanted golden apples to also be cursed.
* Default value: `true`
10. ##### `chance_of_curse`
This parameter sets the chance of a golden apple becoming cursed when enchanted successfully.
* Default value: `0.1`
11. ##### `anvil_requires_secondary_item`
This parameter determines whether a second item is required or not when creating enchanted golden apples using anvil.
* Default value: `true`
12. ##### `anvil_secondary_item_id`
This parameter sets the item that a player has to combine with a golden apple on an anvil to get enchanted golden apple.
Parameter has to be a [namespaced ID](https://minecraft.gamepedia.com/Namespaced_ID) of the item surrounded with double quotes.
* Default value: `"minecraft:nether_star"`

If one or several of these parameters are not present, default value for missing parameters will be used.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings = 1.15.2+build.14
loader_version = 0.7.8+build.189

#Mod properties
mod_version = 0.1.0
mod_version = 0.2.0
maven_group = ru.berdinskiybear.notchify
archives_base_name = notchify

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/ru/berdinskiybear/notchify/NotchifyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public class NotchifyConfig {
private boolean survivalPlayerAlwaysSucceeds;
@SerializedName("enchanting_chance_modifier")
private float enchantingChanceModifier;
@SerializedName("can_golden_apple_vanish")
private boolean canGoldenAppleVanish;
@SerializedName("vanishing_chance")
private float vanishingChance;
@SerializedName("can_enchanted_golden_apple_become_cursed")
private boolean canEGApplesBecomeCursed;
@SerializedName("chance_of_curse")
private float curseChance;
@SerializedName("anvil_requires_secondary_item")
private boolean secondaryItemRequired;
@SerializedName("anvil_secondary_item_id")
private String secondaryItemID;

public NotchifyConfig() {
enableAnvil = true;
Expand All @@ -24,6 +36,12 @@ public NotchifyConfig() {
creativePlayerAlwaysSucceeds = true;
survivalPlayerAlwaysSucceeds = false;
enchantingChanceModifier = 1.0F;
canGoldenAppleVanish = true;
vanishingChance = 0.9F;
canEGApplesBecomeCursed = true;
curseChance = 0.1F;
secondaryItemRequired = true;
secondaryItemID = "minecraft:nether_star";
}

public boolean isAnvilEnabled() {
Expand All @@ -49,4 +67,28 @@ public boolean isSurvivalPlayerAlwaysSuccessful() {
public float getEnchantingChanceModifier() {
return enchantingChanceModifier;
}

public boolean canGoldenAppleVanish() {
return canGoldenAppleVanish;
}

public float getVanishingChance() {
return vanishingChance;
}

public boolean canEGApplesBecomeCursed() {
return canEGApplesBecomeCursed;
}

public float getCurseChance() {
return curseChance;
}

public boolean isSecondaryItemRequired() {
return secondaryItemRequired;
}

public String getSecondaryItemID() {
return secondaryItemID;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package ru.berdinskiybear.notchify.mixins;

import net.minecraft.container.AnvilContainer;
import net.minecraft.container.Container;
import net.minecraft.container.ContainerType;
import net.minecraft.container.Property;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.StringUtils;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,28 +19,43 @@
import ru.berdinskiybear.notchify.NotchifyMod;

@Mixin(AnvilContainer.class)
public class NotchifyUsingAnvil {
public abstract class NotchifyUsingAnvil extends Container {

protected NotchifyUsingAnvil(ContainerType<?> type, int syncId) {
super(type, syncId);
}

@Shadow @Final private Inventory inventory;
@Shadow @Final private Inventory result;
@Shadow private String newItemName;
@Shadow @Final private Property levelCost;

@Inject(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/container/AnvilContainer;sendContentUpdates()V"), cancellable = true)
@Inject(method = "updateResult", at = @At(value = "HEAD"), cancellable = true)
public void notchification(CallbackInfo info) {
if (NotchifyMod.getConfig().isAnvilEnabled()) {
ItemStack leftStack = this.inventory.getInvStack(0);
ItemStack rightStack = this.inventory.getInvStack(1);
ItemStack egapples = new ItemStack(Items.ENCHANTED_GOLDEN_APPLE, 1);

if (leftStack.getItem() == Items.GOLDEN_APPLE && leftStack.getCount() == 1 && rightStack.isEmpty())
if (StringUtils.isBlank(this.newItemName)) {
this.result.setInvStack(0, egapples);
this.levelCost.set(NotchifyMod.getConfig().getEGAppleEnchantmentCost());
} else if (leftStack.hasCustomName() && leftStack.getName().asString().equals(this.newItemName)) {
this.result.setInvStack(0, egapples.setCustomName(leftStack.getName()));
// если предмет слева - золотое яблоко, предмет слева один и либо поле ввода имени пустое, либо предмет слева имеет имя и оно совпадает с текстом в поле ввода
if (leftStack.getItem() == Items.GOLDEN_APPLE && leftStack.getCount() == 1 && (StringUtils.isBlank(this.newItemName) || (leftStack.hasCustomName() && leftStack.getName().asString().equals(this.newItemName)))) {
ItemStack rightStack = this.inventory.getInvStack(1);

// если либо предмет справа необходим и он как в настройках и он один, либо предмет справа не нужен и предмет справа отсутствует
if ((NotchifyMod.getConfig().isSecondaryItemRequired() && rightStack.getItem() == Registry.ITEM.get(new Identifier(NotchifyMod.getConfig().getSecondaryItemID())) && rightStack.getCount() == 1) || (!NotchifyMod.getConfig().isSecondaryItemRequired() && rightStack.isEmpty())) {
ItemStack newApple = new ItemStack(Items.ENCHANTED_GOLDEN_APPLE, 1);
if (leftStack.hasCustomName())
newApple.setCustomName(leftStack.getName());

this.result.setInvStack(0, newApple);
this.levelCost.set(NotchifyMod.getConfig().getEGAppleEnchantmentCost());
} else {
this.result.setInvStack(0, ItemStack.EMPTY);
this.levelCost.set(0);
}

this.sendContentUpdates();

info.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ public void notchification(PlayerEntity player, int id, CallbackInfoReturnable<B
ItemStack lapisStack = this.inventory.getInvStack(1);
int button = id + 1;

if ((!lapisStack.isEmpty() && lapisStack.getCount() >= button && player.experienceLevel > button && player.experienceLevel > this.enchantmentPower[id]) || player.abilities.creativeMode) {
// если либо есть лазурит и его не меньше чем выбранный уровень и у игрока опыта не меньше чем выбранного уровня и уровня зачарования, либо игрок в творческом режиме
if ((!lapisStack.isEmpty() && lapisStack.getCount() >= button && player.experienceLevel >= button && player.experienceLevel >= this.enchantmentPower[id]) || player.abilities.creativeMode) {
this.context.run((world, blockPos) -> {
this.random.setSeed((long) (this.seed.get() + id + 3));
float playerChance = ((float) (enchantmentPower[id]) * NotchifyMod.getConfig().getEnchantingChanceModifier()) / ((float) (NotchifyMod.getConfig().getEGAppleEnchantmentCost()) * 10.0F);
float choice = this.random.nextFloat();

//NotchifyMod.log(playerChance * 100.0F + "%");
float playerChance = ((float) (enchantmentPower[id]) * NotchifyMod.getConfig().getEnchantingChanceModifier()) / ((float) (NotchifyMod.getConfig().getEGAppleEnchantmentCost()) * 10.0F) ;

player.applyEnchantmentCosts(null, button);

Expand All @@ -131,12 +129,17 @@ public void notchification(PlayerEntity player, int id, CallbackInfoReturnable<B
this.inventory.setInvStack(1, ItemStack.EMPTY);
}

if ((choice < playerChance || (player.abilities.creativeMode && NotchifyMod.getConfig().isCreativePlayerAlwaysSuccessful())) || NotchifyMod.getConfig().isSurvivalPlayerAlwaysSuccessful()) {
// если либо игрок или удачлив, или в творческом режиме и настройки это допускают, либо все игроки всегда удачливы
if ((this.random.nextFloat() < playerChance || (player.abilities.creativeMode && NotchifyMod.getConfig().isCreativePlayerAlwaysSuccessful())) || NotchifyMod.getConfig().isSurvivalPlayerAlwaysSuccessful()) {
ItemStack newApple = new ItemStack(Items.ENCHANTED_GOLDEN_APPLE, 1);

if (enchantingStack.hasCustomName())
newApple.setCustomName(enchantingStack.getName());

if (NotchifyMod.getConfig().canEGApplesBecomeCursed() && (this.random.nextFloat() < NotchifyMod.getConfig().getCurseChance())) {
newApple.addEnchantment(Enchantments.VANISHING_CURSE, 1);
}

this.inventory.setInvStack(0, newApple);

player.incrementStat(Stats.ENCHANT_ITEM);
Expand All @@ -146,6 +149,10 @@ public void notchification(PlayerEntity player, int id, CallbackInfoReturnable<B

world.playSound(null, blockPos, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, world.random.nextFloat() * 0.1F + 0.9F);
} else {
if (NotchifyMod.getConfig().canGoldenAppleVanish() && (this.random.nextFloat() < NotchifyMod.getConfig().getVanishingChance())) {
this.inventory.setInvStack(0, ItemStack.EMPTY);
}

world.playSound(null, blockPos, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, world.random.nextFloat() * 0.1F + 2.0F);
}

Expand Down
Binary file modified src/main/resources/assets/notchify/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c074f48

Please sign in to comment.