-
Notifications
You must be signed in to change notification settings - Fork 3
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
2a7643a
commit a4c5b65
Showing
11 changed files
with
203 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ bin | |
.metadata | ||
.classpath | ||
.project | ||
.factorypath | ||
|
||
# idea | ||
out | ||
|
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
58 changes: 58 additions & 0 deletions
58
src/main/java/thecodex6824/thaumcraftfix/core/mixin/item/ItemPrimordialPearlMixin.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,58 @@ | ||
/** | ||
* Thaumcraft Fix | ||
* Copyright (c) 2024 TheCodex6824. | ||
* | ||
* This file is part of Thaumcraft Fix. | ||
* | ||
* Thaumcraft Fix 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. | ||
* | ||
* Thaumcraft Fix 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 Thaumcraft Fix. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package thecodex6824.thaumcraftfix.core.mixin.item; | ||
|
||
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 net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.registry.RegistrySimple; | ||
import thaumcraft.common.items.curios.ItemPrimordialPearl; | ||
|
||
@Mixin(ItemPrimordialPearl.class) | ||
public class ItemPrimordialPearlMixin extends Item { | ||
|
||
// overwrite reason: method doesn't exist in the original class | ||
@Override | ||
public boolean showDurabilityBar(ItemStack stack) { | ||
return stack.getItemDamage() > 0; | ||
} | ||
|
||
// overwrite reason: method doesn't exist in the original class, | ||
// and the super implementation is dangerous (divide by zero risk) | ||
@Override | ||
public double getDurabilityForDisplay(ItemStack stack) { | ||
return stack.getItemDamage() / 8.0; | ||
} | ||
|
||
@Inject(method = "<init>()V", at = @At("RETURN")) | ||
private void construct(CallbackInfo info) { | ||
setMaxDamage(0); | ||
((RegistrySimple<?, ?>) properties).registryObjects.remove(new ResourceLocation("damage")); | ||
((RegistrySimple<?, ?>) properties).registryObjects.remove(new ResourceLocation("damaged")); | ||
setHasSubtypes(true); | ||
} | ||
|
||
} |
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
95 changes: 0 additions & 95 deletions
95
...ex6824/thaumcraftfix/core/transformer/custom/PrimordialPearlDurabilityBarTransformer.java
This file was deleted.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
src/test/java/thecodex6824/thaumcraftfix/test/TestPrimordialPearl.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,51 @@ | ||
package thecodex6824.thaumcraftfix.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import net.minecraft.init.Bootstrap; | ||
import net.minecraft.item.ItemStack; | ||
import thaumcraft.common.items.curios.ItemPrimordialPearl; | ||
|
||
public class TestPrimordialPearl { | ||
|
||
@BeforeAll | ||
static void setup() { | ||
Bootstrap.register(); | ||
} | ||
|
||
static Stream<? extends Arguments> testPearlDurabilityProperties() { | ||
// we are in the normal classloader so this has to be repeated | ||
Bootstrap.register(); | ||
int maxMeta = new ItemStack(new ItemPrimordialPearl()).getMaxDamage(); | ||
return IntStream.rangeClosed(0, maxMeta) | ||
.mapToObj(i -> Arguments.of(i, (double) i / maxMeta)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void testPearlDurabilityProperties(int metadata, double damageRatio) { | ||
ItemPrimordialPearl pearl = new ItemPrimordialPearl(); | ||
ItemStack stack = new ItemStack(pearl, 1, metadata); | ||
assertEquals(metadata != 0, stack.getItem().showDurabilityBar(stack)); | ||
assertEquals(damageRatio, stack.getItem().getDurabilityForDisplay(stack)); | ||
} | ||
|
||
@Test | ||
void testPearlNotDamageable() { | ||
ItemStack pearl = new ItemStack(new ItemPrimordialPearl()); | ||
assertFalse(pearl.isItemStackDamageable()); | ||
assertTrue(pearl.getHasSubtypes()); | ||
} | ||
|
||
} |
Oops, something went wrong.