fix Counter
This commit is contained in:
parent
8e8bc4589b
commit
875bef25b6
2 changed files with 11 additions and 21 deletions
|
@ -1,41 +1,31 @@
|
|||
package org.dimdev.dimdoors.world.level;
|
||||
|
||||
import dev.onyxstudios.cca.api.v3.component.ComponentV3;
|
||||
|
||||
import dev.onyxstudios.cca.api.v3.item.ItemComponent;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Counter implements ComponentV3 {
|
||||
private final ItemStack stack;
|
||||
private int counter;
|
||||
public class Counter extends ItemComponent {
|
||||
|
||||
public Counter(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
super(stack);
|
||||
if (!this.hasTag("counter"))
|
||||
this.putInt("counter", 0);
|
||||
}
|
||||
|
||||
public int increment() {
|
||||
return this.counter++;
|
||||
int counter = count();
|
||||
putInt("counter", counter + 1);
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return this.counter;
|
||||
return getInt("counter");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.counter = 0;
|
||||
putInt("counter", 0);
|
||||
}
|
||||
|
||||
public static <T> Counter get(T provider) {
|
||||
return DimensionalDoorsComponents.COUNTER_COMPONENT_KEY.get(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNbt(CompoundTag tag) {
|
||||
this.counter = tag.getInt("counter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNbt(CompoundTag tag) {
|
||||
tag.putInt("counter", this.counter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ public class DimensionalDoorsComponents implements LevelComponentInitializer, It
|
|||
|
||||
@Override
|
||||
public void registerItemComponentFactories(ItemComponentFactoryRegistry registry) {
|
||||
registry.registerFor(ModItems.RIFT_CONFIGURATION_TOOL, COUNTER_COMPONENT_KEY, Counter::new);
|
||||
registry.register(ModItems.RIFT_CONFIGURATION_TOOL, COUNTER_COMPONENT_KEY, Counter::new);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue