Move items to kotlin
This commit is contained in:
parent
96b1d1ea92
commit
1b790d49c9
@ -142,7 +142,7 @@ public class OverdriveThatMatters {
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(Registry.Stats.class);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(DrivePool.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(ItemPortableCondensationDrive.class);
|
||||
MinecraftForge.EVENT_BUS.register(ItemPortableCondensationDrive.Companion);
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(AndroidCapability::registerEffects);
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.match_nbt", filter.match_nbt ? yes : no));
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.match_nbt", filter.matchNbt ? yes : no));
|
||||
getOrCreateWidget().active = !isWidgetDisabled();
|
||||
} else {
|
||||
getOrCreateWidget().active = false;
|
||||
@ -175,7 +175,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.MATCH_NBT, !filter.match_nbt));
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.MATCH_NBT, !filter.matchNbt));
|
||||
disableFor(20);
|
||||
}
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.match_tag", filter.match_tag ? yes : no));
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.match_tag", filter.matchTag ? yes : no));
|
||||
getOrCreateWidget().active = !isWidgetDisabled();
|
||||
} else {
|
||||
getOrCreateWidget().active = false;
|
||||
@ -203,7 +203,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.MATCH_TAG, !filter.match_tag));
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.MATCH_TAG, !filter.matchTag));
|
||||
disableFor(20);
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.blacklist", filter.blacklist ? yes : no));
|
||||
getOrCreateWidget().setMessage(new TranslatableComponent("otm.filter.blacklist", filter.isBlacklist ? yes : no));
|
||||
getOrCreateWidget().active = !isWidgetDisabled();
|
||||
} else {
|
||||
getOrCreateWidget().active = false;
|
||||
@ -231,7 +231,7 @@ public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
|
||||
var filter = menu.getFilter();
|
||||
|
||||
if (filter != null) {
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.BLACKLIST, !filter.blacklist));
|
||||
MatteryNetworking.send(null, new DriveViewerMenu.FilterSwitchPacket(menu.containerId, DriveViewerMenu.FilterSwitch.BLACKLIST, !filter.isBlacklist));
|
||||
disableFor(20);
|
||||
}
|
||||
}
|
||||
|
@ -246,15 +246,15 @@ public class DriveViewerMenu extends PoweredMatteryMenu implements INetworkedIte
|
||||
|
||||
switch (type) {
|
||||
case MATCH_NBT -> {
|
||||
settings.match_nbt = value;
|
||||
settings.matchNbt = value;
|
||||
}
|
||||
|
||||
case MATCH_TAG -> {
|
||||
settings.match_tag = value;
|
||||
settings.matchTag = value;
|
||||
}
|
||||
|
||||
case BLACKLIST -> {
|
||||
settings.blacklist = value;
|
||||
settings.isBlacklist = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ inline fun CompoundTag.ifHas(s: String, consumer: (Tag) -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
fun CompoundTag.ifHas(s: String, type: Byte, consumer: (Tag) -> Unit) {
|
||||
inline fun CompoundTag.ifHas(s: String, type: Byte, consumer: (Tag) -> Unit) {
|
||||
val tag = get(s)
|
||||
|
||||
if (tag != null && tag.id == type) {
|
||||
@ -47,7 +47,7 @@ fun CompoundTag.ifHas(s: String, type: Byte, consumer: (Tag) -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Tag> CompoundTag.ifHas(s: String, type: Class<T>, consumer: (T) -> Unit) {
|
||||
inline fun <T : Tag> CompoundTag.ifHas(s: String, type: Class<T>, consumer: (T) -> Unit) {
|
||||
val tag = get(s)
|
||||
|
||||
if (tag != null && tag::class.java == type) {
|
||||
|
@ -136,7 +136,10 @@ object DrivePool {
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isLegalAccess(): Boolean {
|
||||
return serverThread == null || Thread.currentThread() === serverThread
|
||||
if (serverThread == null)
|
||||
return false
|
||||
|
||||
return Thread.currentThread() === serverThread
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
|
@ -1,207 +1,156 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.core.Fraction;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.core.Fraction.Companion.deserializeNBT
|
||||
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import net.minecraftforge.energy.CapabilityEnergy
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Rarity
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
import ru.dbotthepony.mc.otm.core.Fraction
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemBattery extends Item {
|
||||
public class BatteryMatteryCapability implements IMatteryEnergyStorage, ICapabilityProvider {
|
||||
private final Fraction storage;
|
||||
private final Fraction max_input;
|
||||
private final Fraction max_output;
|
||||
private final boolean is_creative;
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
private Fraction energy() {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
if (tag.contains("otm_energy")) {
|
||||
return Fraction.deserializeNBT(tag.get("otm_energy"));
|
||||
class ItemBattery : Item {
|
||||
private inner class BatteryMatteryCapability(private val stack: ItemStack) : IMatteryEnergyStorage, ICapabilityProvider {
|
||||
private fun energy(): Fraction {
|
||||
val tag = stack.orCreateTag
|
||||
return if (tag.contains("otm_energy")) {
|
||||
deserializeNBT(tag["otm_energy"])
|
||||
} else Fraction.ZERO
|
||||
}
|
||||
|
||||
return Fraction.ZERO;
|
||||
private fun energy(value: Fraction) {
|
||||
stack.getOrCreateTag().put("otm_energy", value.serializeNBT())
|
||||
}
|
||||
|
||||
private void energy(Fraction value) {
|
||||
stack.getOrCreateTag().put("otm_energy", value.serializeNBT());
|
||||
override fun extractEnergyOuter(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
return extractEnergyInner(howMuch, simulate)
|
||||
}
|
||||
|
||||
public BatteryMatteryCapability(ItemStack stack, Fraction storage, Fraction max_input, Fraction max_output) {
|
||||
this.stack = stack;
|
||||
is_creative = false;
|
||||
this.storage = storage;
|
||||
this.max_input = max_input;
|
||||
this.max_output = max_output;
|
||||
}
|
||||
|
||||
public BatteryMatteryCapability(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
is_creative = true;
|
||||
storage = MatteryCapability.LONG_MAX_VALUE;
|
||||
max_input = MatteryCapability.LONG_MAX_VALUE;
|
||||
max_output = MatteryCapability.LONG_MAX_VALUE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction extractEnergyOuter(@Nonnull Fraction howMuch, boolean simulate) {
|
||||
return extractEnergyInner(howMuch, simulate);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction extractEnergyInner(@Nonnull Fraction howMuch, boolean simulate) {
|
||||
if (is_creative)
|
||||
return howMuch;
|
||||
|
||||
Fraction new_energy = energy().minus(howMuch.min(max_output)).moreThanZero();
|
||||
Fraction diff = energy().minus(new_energy);
|
||||
override fun extractEnergyInner(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
if (isCreative) return howMuch
|
||||
val new = energy().minus(howMuch.min(extract)).moreThanZero()
|
||||
val diff = energy().minus(new)
|
||||
|
||||
if (!simulate) {
|
||||
energy(new_energy);
|
||||
energy(new)
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction receiveEnergyOuter(@Nonnull Fraction howMuch, boolean simulate) {
|
||||
return receiveEnergyInner(howMuch, simulate);
|
||||
override fun receiveEnergyOuter(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
return receiveEnergyInner(howMuch, simulate)
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction receiveEnergyInner(@Nonnull Fraction howMuch, boolean simulate) {
|
||||
if (is_creative)
|
||||
return howMuch;
|
||||
|
||||
Fraction new_energy = energy().plus(howMuch.min(max_input)).min(storage);
|
||||
Fraction diff = new_energy.minus(energy());
|
||||
override fun receiveEnergyInner(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
if (isCreative) return howMuch
|
||||
val new = energy().plus(howMuch.min(receive)).min(storage)
|
||||
val diff = new.minus(energy())
|
||||
|
||||
if (!simulate) {
|
||||
energy(new_energy);
|
||||
energy(new)
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getMissingPower() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return IMatteryEnergyStorage.super.getMissingPower();
|
||||
override fun getMissingPower(): Fraction {
|
||||
return if (isCreative) MatteryCapability.LONG_MAX_VALUE else super.getMissingPower()
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getBatteryLevel() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return energy();
|
||||
override fun getBatteryLevel(): Fraction {
|
||||
return if (isCreative) MatteryCapability.LONG_MAX_VALUE else energy()
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getMaxBatteryLevel() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return storage;
|
||||
override fun getMaxBatteryLevel(): Fraction {
|
||||
return storage
|
||||
}
|
||||
|
||||
private final LazyOptional<IMatteryEnergyStorage> resolver = LazyOptional.of(() -> this);
|
||||
private val resolver = LazyOptional.of<IMatteryEnergyStorage> { this }
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (cap == MatteryCapability.ENERGY || cap == CapabilityEnergy.ENERGY)
|
||||
return resolver.cast();
|
||||
|
||||
return LazyOptional.empty();
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
return if (cap === MatteryCapability.ENERGY || cap === CapabilityEnergy.ENERGY) resolver.cast() else LazyOptional.empty()
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return true;
|
||||
override fun canExtract(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return true;
|
||||
override fun canReceive(): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean is_creative;
|
||||
private val isCreative: Boolean
|
||||
val storage: Fraction
|
||||
val receive: Fraction
|
||||
val extract: Fraction
|
||||
private val throughputText: Component
|
||||
|
||||
public final Fraction storage;
|
||||
public final Fraction receive;
|
||||
public final Fraction extract;
|
||||
|
||||
private final Component THROUGHPUT;
|
||||
private static final Component INFINITE_STORAGE = new TranslatableComponent("otm.item.power.infinite.storage").withStyle(ChatFormatting.GRAY);
|
||||
|
||||
public ItemBattery(Fraction storage, Fraction receive, Fraction extract) {
|
||||
super(new Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||
is_creative = false;
|
||||
this.storage = storage;
|
||||
this.receive = receive;
|
||||
this.extract = extract;
|
||||
THROUGHPUT = new TranslatableComponent("otm.item.power.normal.throughput", FormattingHelper.formatPower(receive), FormattingHelper.formatPower(extract)).withStyle(ChatFormatting.GRAY);
|
||||
constructor(storage: Fraction, receive: Fraction, extract: Fraction) : super(
|
||||
Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)
|
||||
) {
|
||||
isCreative = false
|
||||
this.storage = storage
|
||||
this.receive = receive
|
||||
this.extract = extract
|
||||
throughputText = TranslatableComponent(
|
||||
"otm.item.power.normal.throughput",
|
||||
FormattingHelper.formatPower(receive),
|
||||
FormattingHelper.formatPower(extract)
|
||||
).withStyle(ChatFormatting.GRAY)
|
||||
}
|
||||
|
||||
public ItemBattery() {
|
||||
super(new Properties().stacksTo(1).rarity(Rarity.EPIC).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||
is_creative = true;
|
||||
this.storage = MatteryCapability.LONG_MAX_VALUE;
|
||||
this.receive = MatteryCapability.LONG_MAX_VALUE;
|
||||
this.extract = MatteryCapability.LONG_MAX_VALUE;
|
||||
THROUGHPUT = new TranslatableComponent("otm.item.power.infinite.throughput").withStyle(ChatFormatting.GRAY);
|
||||
constructor() : super(Properties().stacksTo(1).rarity(Rarity.EPIC).tab(OverdriveThatMatters.CREATIVE_TAB)) {
|
||||
isCreative = true
|
||||
storage = MatteryCapability.LONG_MAX_VALUE
|
||||
receive = MatteryCapability.LONG_MAX_VALUE
|
||||
extract = MatteryCapability.LONG_MAX_VALUE
|
||||
throughputText = TranslatableComponent("otm.item.power.infinite.throughput").withStyle(ChatFormatting.GRAY)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_);
|
||||
|
||||
if (is_creative) {
|
||||
p_41423_.add(INFINITE_STORAGE);
|
||||
p_41423_.add(THROUGHPUT);
|
||||
override fun appendHoverText(
|
||||
stack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
p_41423_: MutableList<Component>,
|
||||
p_41424_: TooltipFlag
|
||||
) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_)
|
||||
if (isCreative) {
|
||||
p_41423_.add(INFINITE_STORAGE)
|
||||
p_41423_.add(throughputText)
|
||||
} else {
|
||||
stack.getCapability(MatteryCapability.ENERGY).ifPresent(cap ->
|
||||
p_41423_.add(new TranslatableComponent("otm.item.power.normal.storage", FormattingHelper.formatPower(cap.getBatteryLevel()), FormattingHelper.formatPower(cap.getMaxBatteryLevel())).withStyle(ChatFormatting.GRAY))
|
||||
);
|
||||
|
||||
p_41423_.add(THROUGHPUT);
|
||||
stack.getCapability(MatteryCapability.ENERGY).ifPresent { cap: IMatteryEnergyStorage ->
|
||||
p_41423_.add(
|
||||
TranslatableComponent(
|
||||
"otm.item.power.normal.storage",
|
||||
FormattingHelper.formatPower(cap.batteryLevel),
|
||||
FormattingHelper.formatPower(cap.maxBatteryLevel)
|
||||
).withStyle(ChatFormatting.GRAY)
|
||||
)
|
||||
}
|
||||
p_41423_.add(throughputText)
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
if (is_creative)
|
||||
return new BatteryMatteryCapability(stack);
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
return BatteryMatteryCapability(stack)
|
||||
}
|
||||
|
||||
return new BatteryMatteryCapability(stack, storage, receive, extract);
|
||||
companion object {
|
||||
private val INFINITE_STORAGE: Component =
|
||||
TranslatableComponent("otm.item.power.infinite.storage").withStyle(ChatFormatting.GRAY)
|
||||
}
|
||||
}
|
@ -1,37 +1,55 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import ru.dbotthepony.mc.otm.item.ItemGravitationalDisruptor
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Rarity
|
||||
import net.minecraft.world.level.Level
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemGravitationalDisruptor extends Item {
|
||||
public ItemGravitationalDisruptor() {
|
||||
super(new Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1).rarity(Rarity.EPIC));
|
||||
class ItemGravitationalDisruptor :
|
||||
Item(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1).rarity(Rarity.EPIC)) {
|
||||
override fun appendHoverText(
|
||||
p_41421_: ItemStack,
|
||||
p_41422_: Level?,
|
||||
list: MutableList<Component>,
|
||||
p_41424_: TooltipFlag
|
||||
) {
|
||||
super.appendHoverText(p_41421_, p_41422_, list, p_41424_)
|
||||
list.add(DESCRIPTION)
|
||||
list.add(DESCRIPTION2)
|
||||
list.add(DESCRIPTION3)
|
||||
list.add(DESCRIPTION4)
|
||||
}
|
||||
|
||||
private static final Component DESCRIPTION = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description").withStyle(ChatFormatting.GRAY);
|
||||
private static final Component DESCRIPTION2 = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description2").withStyle(ChatFormatting.GRAY);
|
||||
private static final Component DESCRIPTION3 = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description3").withStyle(ChatFormatting.DARK_RED);
|
||||
private static final Component DESCRIPTION4 = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description4",
|
||||
new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description4_clarification").withStyle(ChatFormatting.DARK_RED, ChatFormatting.BOLD, ChatFormatting.UNDERLINE),
|
||||
new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description4_clarification2").withStyle(ChatFormatting.DARK_RED, ChatFormatting.ITALIC)
|
||||
).withStyle(ChatFormatting.DARK_RED);
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack p_41421_, @Nullable Level p_41422_, List<Component> list, TooltipFlag p_41424_) {
|
||||
super.appendHoverText(p_41421_, p_41422_, list, p_41424_);
|
||||
list.add(DESCRIPTION);
|
||||
list.add(DESCRIPTION2);
|
||||
list.add(DESCRIPTION3);
|
||||
list.add(DESCRIPTION4);
|
||||
companion object {
|
||||
private val DESCRIPTION: Component =
|
||||
TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description").withStyle(
|
||||
ChatFormatting.GRAY
|
||||
)
|
||||
private val DESCRIPTION2: Component =
|
||||
TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description2").withStyle(
|
||||
ChatFormatting.GRAY
|
||||
)
|
||||
private val DESCRIPTION3: Component =
|
||||
TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description3").withStyle(
|
||||
ChatFormatting.DARK_RED
|
||||
)
|
||||
private val DESCRIPTION4: Component = TranslatableComponent(
|
||||
"item.overdrive_that_matters.gravitational_disruptor.description4",
|
||||
TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description4_clarification").withStyle(
|
||||
ChatFormatting.DARK_RED,
|
||||
ChatFormatting.BOLD,
|
||||
ChatFormatting.UNDERLINE
|
||||
),
|
||||
TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description4_clarification2").withStyle(
|
||||
ChatFormatting.DARK_RED,
|
||||
ChatFormatting.ITALIC
|
||||
)
|
||||
).withStyle(ChatFormatting.DARK_RED)
|
||||
}
|
||||
}
|
@ -1,207 +1,142 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.core.Fraction;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.MethodsReturnNonnullByDefault
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.Rarity
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler.MatterDirection
|
||||
import ru.dbotthepony.mc.otm.core.Fraction
|
||||
import ru.dbotthepony.mc.otm.core.Fraction.Companion.deserializeNBT
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper
|
||||
import javax.annotation.ParametersAreNonnullByDefault
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
public class ItemMatterCapacitor extends Item {
|
||||
public static class ItemMatterCapacitorCapability implements ICapabilityProvider, IMatterHandler {
|
||||
private final LazyOptional<IMatterHandler> resolver = LazyOptional.of(() -> this);
|
||||
class ItemMatterCapacitor : Item {
|
||||
private inner class ItemMatterCapacitorCapability(private val stack: ItemStack) : ICapabilityProvider, IMatterHandler {
|
||||
private val resolver = LazyOptional.of<IMatterHandler> { this }
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (cap == MatteryCapability.MATTER)
|
||||
return resolver.cast();
|
||||
|
||||
return LazyOptional.empty();
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
return if (cap === MatteryCapability.MATTER) resolver.cast() else LazyOptional.empty()
|
||||
}
|
||||
|
||||
private final Fraction storage;
|
||||
private final Fraction max_input;
|
||||
private final Fraction max_output;
|
||||
private final boolean is_creative;
|
||||
private Fraction energy;
|
||||
private String _energy;
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
private Fraction matter() {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
if (tag.contains("otm_matter")) {
|
||||
return Fraction.deserializeNBT(tag.get("otm_matter"));
|
||||
private fun matter(): Fraction {
|
||||
val tag = stack.orCreateTag
|
||||
return if (tag.contains("otm_matter")) {
|
||||
deserializeNBT(tag["otm_matter"])
|
||||
} else Fraction.ZERO
|
||||
}
|
||||
|
||||
return Fraction.ZERO;
|
||||
private fun matter(value: Fraction) {
|
||||
stack.getOrCreateTag().put("otm_matter", value.serializeNBT())
|
||||
}
|
||||
|
||||
private void matter(Fraction value) {
|
||||
stack.getOrCreateTag().put("otm_matter", value.serializeNBT());
|
||||
override fun getStoredMatter(): Fraction {
|
||||
return if (isCreative) Fraction.LONG_MAX_VALUE else matter()
|
||||
}
|
||||
|
||||
public ItemMatterCapacitorCapability(ItemStack stack, Fraction storage, Fraction max_input, Fraction max_output) {
|
||||
this.stack = stack;
|
||||
is_creative = false;
|
||||
this.storage = storage;
|
||||
this.max_input = max_input;
|
||||
this.max_output = max_output;
|
||||
override fun getMaxStoredMatter(): Fraction {
|
||||
return storage
|
||||
}
|
||||
|
||||
public ItemMatterCapacitorCapability(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
is_creative = true;
|
||||
storage = MatteryCapability.LONG_MAX_VALUE;
|
||||
max_input = MatteryCapability.LONG_MAX_VALUE;
|
||||
max_output = MatteryCapability.LONG_MAX_VALUE;
|
||||
override fun getMissingMatter(): Fraction {
|
||||
return if (isCreative) Fraction.LONG_MAX_VALUE else super.getMissingMatter()
|
||||
}
|
||||
|
||||
public ItemMatterCapacitorCapability(ItemStack stack, Fraction storage) {
|
||||
this.stack = stack;
|
||||
is_creative = false;
|
||||
this.storage = storage;
|
||||
max_input = MatteryCapability.LONG_MAX_VALUE;
|
||||
max_output = MatteryCapability.LONG_MAX_VALUE;
|
||||
override fun receiveMatterOuter(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
return receiveMatterInner(howMuch, simulate)
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getStoredMatter() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return matter();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getMaxStoredMatter() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction getMissingMatter() {
|
||||
if (is_creative)
|
||||
return MatteryCapability.LONG_MAX_VALUE;
|
||||
|
||||
return IMatterHandler.super.getMissingMatter();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction receiveMatterOuter(Fraction howMuch, boolean simulate) {
|
||||
return receiveMatterInner(howMuch, simulate);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction receiveMatterInner(Fraction howMuch, boolean simulate) {
|
||||
if (is_creative)
|
||||
return howMuch;
|
||||
|
||||
Fraction new_matter = matter().plus(howMuch.min(max_input)).min(storage);
|
||||
Fraction diff = new_matter.minus(matter());
|
||||
override fun receiveMatterInner(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
if (isCreative) return howMuch
|
||||
val new = matter().plus(howMuch.min(maxInput)).min(storage)
|
||||
val diff = new.minus(matter())
|
||||
|
||||
if (!simulate) {
|
||||
matter(new_matter);
|
||||
matter(new)
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction extractMatterOuter(Fraction howMuch, boolean simulate) {
|
||||
return extractMatterInner(howMuch, simulate);
|
||||
override fun extractMatterOuter(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
return extractMatterInner(howMuch, simulate)
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Fraction extractMatterInner(Fraction howMuch, boolean simulate) {
|
||||
if (is_creative)
|
||||
return howMuch;
|
||||
|
||||
|
||||
Fraction new_matter = matter().minus(howMuch.min(max_output)).moreThanZero();
|
||||
Fraction diff = matter().minus(new_matter);
|
||||
override fun extractMatterInner(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
if (isCreative) return howMuch
|
||||
val new = matter().minus(howMuch.min(maxOutput)).moreThanZero()
|
||||
val diff = matter().minus(new)
|
||||
|
||||
if (!simulate) {
|
||||
matter(new_matter);
|
||||
matter(new)
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MatterDirection getDirection() {
|
||||
return MatterDirection.BIDIRECTIONAL;
|
||||
override fun getDirection(): MatterDirection {
|
||||
return MatterDirection.BIDIRECTIONAL
|
||||
}
|
||||
}
|
||||
|
||||
public final Fraction storage;
|
||||
val storage: Fraction
|
||||
private val isCreative: Boolean
|
||||
|
||||
private static final Component INFINITE_STORAGE = new TranslatableComponent("otm.item.matter.infinite").withStyle(ChatFormatting.GRAY);
|
||||
|
||||
private final boolean is_creative;
|
||||
|
||||
public ItemMatterCapacitor(Fraction storage) {
|
||||
super(new Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||
is_creative = false;
|
||||
this.storage = storage;
|
||||
constructor(storage: Fraction) : super(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)) {
|
||||
isCreative = false
|
||||
this.storage = storage
|
||||
}
|
||||
|
||||
public ItemMatterCapacitor() {
|
||||
super(new Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB).rarity(Rarity.EPIC));
|
||||
is_creative = true;
|
||||
storage = MatteryCapability.LONG_MAX_VALUE;
|
||||
constructor() : super(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB).rarity(Rarity.EPIC)) {
|
||||
isCreative = true
|
||||
storage = MatteryCapability.LONG_MAX_VALUE
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_);
|
||||
|
||||
if (is_creative) {
|
||||
p_41423_.add(INFINITE_STORAGE);
|
||||
override fun appendHoverText(
|
||||
stack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
p_41423_: MutableList<Component>,
|
||||
p_41424_: TooltipFlag
|
||||
) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_)
|
||||
if (isCreative) {
|
||||
p_41423_.add(INFINITE_STORAGE)
|
||||
} else {
|
||||
stack.getCapability(MatteryCapability.MATTER).ifPresent(cap ->
|
||||
p_41423_.add(new TranslatableComponent("otm.item.matter.normal", FormattingHelper.formatMatterValuePlain(cap.getStoredMatter()), FormattingHelper.formatMatterValuePlain(storage)).withStyle(ChatFormatting.GRAY))
|
||||
);
|
||||
stack.getCapability(MatteryCapability.MATTER).ifPresent { cap: IMatterHandler ->
|
||||
p_41423_.add(
|
||||
TranslatableComponent(
|
||||
"otm.item.matter.normal",
|
||||
FormattingHelper.formatMatterValuePlain(cap.storedMatter),
|
||||
FormattingHelper.formatMatterValuePlain(storage)
|
||||
).withStyle(ChatFormatting.GRAY)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
if (is_creative)
|
||||
return new ItemMatterCapacitorCapability(stack);
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
return ItemMatterCapacitorCapability(stack)
|
||||
}
|
||||
|
||||
return new ItemMatterCapacitorCapability(stack, storage);
|
||||
companion object {
|
||||
private val maxInput = MatteryCapability.LONG_MAX_VALUE
|
||||
private val maxOutput = MatteryCapability.LONG_MAX_VALUE
|
||||
|
||||
private val INFINITE_STORAGE: Component =
|
||||
TranslatableComponent("otm.item.matter.infinite").withStyle(ChatFormatting.GRAY)
|
||||
}
|
||||
}
|
@ -1,180 +1,166 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternInsertStatus;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import net.minecraft.ChatFormatting
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.network.chat.Component
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternInsertStatus
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
import ru.dbotthepony.mc.otm.ifHas
|
||||
import java.util.*
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
class ItemPatternStorage : Item {
|
||||
val capacity: Int
|
||||
var isCreative: Boolean
|
||||
|
||||
public class ItemPatternStorage extends Item {
|
||||
public final int capacity;
|
||||
public boolean is_creative;
|
||||
|
||||
public ItemPatternStorage(int capacity) {
|
||||
super(new Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1));
|
||||
this.capacity = capacity;
|
||||
is_creative = false;
|
||||
constructor(capacity: Int) : super(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1)) {
|
||||
this.capacity = capacity
|
||||
isCreative = false
|
||||
}
|
||||
|
||||
public ItemPatternStorage() {
|
||||
super(new Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1));
|
||||
is_creative = true;
|
||||
capacity = Integer.MAX_VALUE;
|
||||
constructor() : super(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1)) {
|
||||
isCreative = true
|
||||
capacity = Int.MAX_VALUE
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
return new ItemPatternStorageCapability(stack, capacity);
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider? {
|
||||
return ItemPatternStorageCapability(stack)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack p_41421_, @Nullable Level p_41422_, List<Component> list, TooltipFlag p_41424_) {
|
||||
p_41421_.getCapability(MatteryCapability.PATTERN).ifPresent(capability -> {
|
||||
if (is_creative)
|
||||
list.add(new TranslatableComponent("otm.item.pattern.infinite.stored", capability.getStored()).withStyle(ChatFormatting.GRAY));
|
||||
override fun appendHoverText(
|
||||
p_41421_: ItemStack,
|
||||
p_41422_: Level?,
|
||||
list: MutableList<Component>,
|
||||
p_41424_: TooltipFlag
|
||||
) {
|
||||
p_41421_.getCapability(MatteryCapability.PATTERN).ifPresent {
|
||||
if (isCreative)
|
||||
list.add(TranslatableComponent("otm.item.pattern.infinite.stored", it.stored).withStyle(ChatFormatting.GRAY))
|
||||
else
|
||||
list.add(new TranslatableComponent("otm.item.pattern.stored", capability.getStored(), capability.getCapacity()).withStyle(ChatFormatting.GRAY));
|
||||
list.add(TranslatableComponent("otm.item.pattern.stored", it.stored, it.capacity).withStyle(ChatFormatting.GRAY))
|
||||
|
||||
for (PatternState state : capability.getStoredPatterns()) {
|
||||
list.add(new TranslatableComponent("otm.item.pattern.line", state.item().getName(new ItemStack(state.item(), 1)), String.format("%.2f", state.research_percent() * 100d)).withStyle(ChatFormatting.AQUA));
|
||||
for (state in it.storedPatterns) {
|
||||
list.add(
|
||||
TranslatableComponent(
|
||||
"otm.item.pattern.line",
|
||||
state.item().getName(ItemStack(state.item(), 1)),
|
||||
String.format("%.2f", state.research_percent() * 100.0)
|
||||
).withStyle(ChatFormatting.AQUA)
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
super.appendHoverText(p_41421_, p_41422_, list, p_41424_);
|
||||
}
|
||||
|
||||
public static class ItemPatternStorageCapability implements IPatternStorage, ICapabilityProvider {
|
||||
private final LazyOptional<IPatternStorage> resolver = LazyOptional.of(() -> this);
|
||||
public final ItemStack stack;
|
||||
public final int capacity;
|
||||
|
||||
public ItemPatternStorageCapability(ItemStack stack, int capacity) {
|
||||
this.stack = stack;
|
||||
this.capacity = capacity;
|
||||
super.appendHoverText(p_41421_, p_41422_, list, p_41424_)
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
private inner class ItemPatternStorageCapability(val stack: ItemStack) : IPatternStorage, ICapabilityProvider {
|
||||
private val resolver = LazyOptional.of<IPatternStorage> { this }
|
||||
|
||||
override fun getCapacity(): Int {
|
||||
return this@ItemPatternStorage.capacity
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStoredPatterns().size();
|
||||
override fun getStored(): Int {
|
||||
return storedPatterns.size
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (cap == MatteryCapability.PATTERN)
|
||||
return resolver.cast();
|
||||
|
||||
return LazyOptional.empty();
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
return if (cap === MatteryCapability.PATTERN) resolver.cast() else LazyOptional.empty()
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<PatternState> getStoredPatterns() {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
override fun getStoredPatterns(): Collection<PatternState> {
|
||||
stack.tag?.ifHas("otm_patterns", ListTag::class.java) {
|
||||
val list = ArrayList<PatternState>()
|
||||
|
||||
if (!tag.contains("otm_patterns") || !(tag.get("otm_patterns") instanceof ListTag))
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
ListTag list = tag.getList("otm_patterns", Tag.TAG_COMPOUND);
|
||||
ArrayList<PatternState> state_list = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
var state = PatternState.deserializeNBT(list.getCompound(i));
|
||||
for (tag in it) {
|
||||
if (tag is CompoundTag) {
|
||||
val state = PatternState.deserializeNBT(tag)
|
||||
|
||||
if (state != null)
|
||||
state_list.add(state);
|
||||
list.add(state)
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableList.copyOf(state_list);
|
||||
return list
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatternInsertStatus insertPattern(PatternState pattern, boolean only_update, boolean simulate) {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
ListTag list;
|
||||
override fun insertPattern(
|
||||
pattern: PatternState,
|
||||
only_update: Boolean,
|
||||
simulate: Boolean
|
||||
): PatternInsertStatus {
|
||||
val tag = stack.orCreateTag
|
||||
var list = tag["otm_patterns"]
|
||||
|
||||
if (tag.get("otm_patterns") instanceof ListTag list1) {
|
||||
list = list1;
|
||||
} else {
|
||||
if (list !is ListTag) {
|
||||
if (only_update)
|
||||
return new PatternInsertStatus();
|
||||
return PatternInsertStatus()
|
||||
|
||||
if (simulate) {
|
||||
if (capacity > 0)
|
||||
return new PatternInsertStatus(pattern);
|
||||
return PatternInsertStatus(pattern)
|
||||
else
|
||||
return new PatternInsertStatus();
|
||||
return PatternInsertStatus()
|
||||
}
|
||||
|
||||
list = new ListTag();
|
||||
tag.put("otm_patterns", list);
|
||||
list = ListTag()
|
||||
tag.put("otm_patterns", list)
|
||||
}
|
||||
|
||||
String compare_with = Objects.requireNonNull(pattern.item().getRegistryName()).toString();
|
||||
var invalidCounter = 0
|
||||
|
||||
int invalid_entries = 0;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
var state = PatternState.deserializeNBT(list.getCompound(i));
|
||||
for (i in list.indices) {
|
||||
val state = PatternState.deserializeNBT(list.getCompound(i))
|
||||
|
||||
if (state != null) {
|
||||
if (state.equals(pattern)) {
|
||||
if (state == pattern) {
|
||||
if (!simulate) {
|
||||
list.set(i, pattern.serializeNBT());
|
||||
list[i] = pattern.serializeNBT()
|
||||
}
|
||||
|
||||
return new PatternInsertStatus(pattern, state);
|
||||
return PatternInsertStatus(pattern, state)
|
||||
}
|
||||
} else {
|
||||
invalid_entries++;
|
||||
invalidCounter++
|
||||
}
|
||||
}
|
||||
|
||||
if (only_update || capacity <= list.size() - invalid_entries)
|
||||
return new PatternInsertStatus();
|
||||
if (only_update || capacity <= list.size - invalidCounter)
|
||||
return PatternInsertStatus()
|
||||
|
||||
if (invalid_entries > 0) {
|
||||
if (invalidCounter > 0) {
|
||||
if (simulate)
|
||||
return new PatternInsertStatus(pattern);
|
||||
return PatternInsertStatus(pattern)
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
var state = PatternState.deserializeNBT(list.getCompound(i));
|
||||
for (i in list.indices) {
|
||||
val state = PatternState.deserializeNBT(list.getCompound(i))
|
||||
|
||||
if (state == null) {
|
||||
list.set(i, pattern.serializeNBT());
|
||||
return new PatternInsertStatus(pattern);
|
||||
list[i] = pattern.serializeNBT()
|
||||
return PatternInsertStatus(pattern)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!simulate)
|
||||
list.add(pattern.serializeNBT());
|
||||
list.add(pattern.serializeNBT())
|
||||
|
||||
return new PatternInsertStatus(pattern);
|
||||
return PatternInsertStatus(pattern)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,268 +1,261 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.drive.DrivePool;
|
||||
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive;
|
||||
import ru.dbotthepony.mc.otm.capability.drive.ItemMatteryDrive;
|
||||
import ru.dbotthepony.mc.otm.core.Fraction;
|
||||
import ru.dbotthepony.mc.otm.capability.drive.DrivePool.isLegalAccess
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive
|
||||
import ru.dbotthepony.mc.otm.capability.drive.ItemMatteryDrive
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.TextComponent
|
||||
import net.minecraft.stats.Stats
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
import net.minecraftforge.event.ForgeEventFactory
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent
|
||||
import ru.dbotthepony.mc.otm.capability.drive.DrivePool
|
||||
import ru.dbotthepony.mc.otm.core.Fraction
|
||||
import ru.dbotthepony.mc.otm.set
|
||||
import java.util.*
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
class ItemPortableCondensationDrive(capacity: Int) :
|
||||
Item(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)) {
|
||||
val capacity: Fraction
|
||||
|
||||
public class ItemPortableCondensationDrive extends Item {
|
||||
public final Fraction capacity;
|
||||
|
||||
public ItemPortableCondensationDrive(int capacity) {
|
||||
super(new Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||
this.capacity = new Fraction(capacity);
|
||||
init {
|
||||
this.capacity = Fraction(capacity)
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPickupEvent(EntityItemPickupEvent event) {
|
||||
if (
|
||||
event.getItem().getOwner() != null &&
|
||||
!event.getItem().getOwner().equals(event.getPlayer().getUUID()) &&
|
||||
event.getItem().getAge() < 200
|
||||
) {
|
||||
return;
|
||||
private inner class DriveCapability(private val stack: ItemStack) : ICapabilityProvider {
|
||||
private var uuid: UUID? = null
|
||||
|
||||
private val resolver = LazyOptional.of<IMatteryDrive<*>> {
|
||||
if (!isLegalAccess()) {
|
||||
return@of ItemMatteryDrive.DUMMY
|
||||
}
|
||||
|
||||
var amount = event.getItem().getItem().getCount();
|
||||
var item = event.getItem().getItem().getItem();
|
||||
val uuid = uuid
|
||||
|
||||
for (var stack : event.getPlayer().getInventory().items) {
|
||||
if (stack.getItem() instanceof ItemPortableCondensationDrive drive) {
|
||||
var _cap = stack.getCapability(MatteryCapability.DRIVE).resolve();
|
||||
|
||||
if (_cap.isPresent()) {
|
||||
var cap = (ItemMatteryDrive) _cap.get();
|
||||
var filter = drive.getFilterSettings(stack);
|
||||
|
||||
if (filter.matches(event.getItem().getItem())) {
|
||||
var copy = event.getItem().getItem().copy();
|
||||
var remaining = cap.insertObject(event.getItem().getItem(), false);
|
||||
|
||||
if (remaining.getCount() == event.getItem().getItem().getCount()) {
|
||||
continue;
|
||||
DrivePool.get(uuid!!, { tag: CompoundTag? ->
|
||||
val drive = ItemMatteryDrive(capacity, uuid)
|
||||
drive.deserializeNBT(tag!!)
|
||||
drive
|
||||
}, { ItemMatteryDrive(capacity, uuid) })
|
||||
}
|
||||
|
||||
copy.setCount(copy.getCount() - remaining.getCount());
|
||||
|
||||
event.setCanceled(true);
|
||||
|
||||
ForgeEventFactory.firePlayerItemPickupEvent(event.getPlayer(), event.getItem(), copy);
|
||||
|
||||
if (remaining.getCount() > 0) {
|
||||
event.getItem().getItem().setCount(remaining.getCount());
|
||||
event.getPlayer().take(event.getItem(), amount - remaining.getCount());
|
||||
|
||||
event.getPlayer().awardStat(Stats.ITEM_PICKED_UP.get(item), amount - remaining.getCount());
|
||||
event.getPlayer().onItemPickup(event.getItem());
|
||||
|
||||
amount = remaining.getCount();
|
||||
} else {
|
||||
event.getPlayer().take(event.getItem(), amount);
|
||||
|
||||
event.getPlayer().awardStat(Stats.ITEM_PICKED_UP.get(item), amount);
|
||||
event.getPlayer().onItemPickup(event.getItem());
|
||||
|
||||
event.getItem().discard();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DriveCapability implements ICapabilityProvider {
|
||||
private UUID uuid;
|
||||
private final ItemStack stack;
|
||||
|
||||
private final LazyOptional<IMatteryDrive> resolver = LazyOptional.of(() -> {
|
||||
if (!DrivePool.isLegalAccess()) {
|
||||
return ItemMatteryDrive.DUMMY;
|
||||
}
|
||||
|
||||
final var uuid = this.uuid;
|
||||
|
||||
return DrivePool.get(uuid, (tag) -> {
|
||||
var drive = new ItemMatteryDrive(capacity, uuid);
|
||||
drive.deserializeNBT(tag);
|
||||
return drive;
|
||||
}, () -> new ItemMatteryDrive(capacity, uuid));
|
||||
});
|
||||
|
||||
DriveCapability(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (cap == MatteryCapability.DRIVE) {
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
if (cap === MatteryCapability.DRIVE) {
|
||||
if (uuid == null) {
|
||||
var get_value = stack.getOrCreateTag().getLongArray("uuid");
|
||||
val array = stack.orCreateTag.getLongArray("uuid")
|
||||
|
||||
if (get_value.length == 2) {
|
||||
uuid = new UUID(get_value[0], get_value[1]);
|
||||
if (array.size == 2) {
|
||||
uuid = UUID(array[0], array[1])
|
||||
} else {
|
||||
uuid = UUID.randomUUID();
|
||||
stack.getOrCreateTag().putLongArray("uuid", new long[] { uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() });
|
||||
uuid = UUID.randomUUID()
|
||||
stack.orCreateTag.putLongArray("uuid", longArrayOf(uuid!!.mostSignificantBits, uuid!!.leastSignificantBits))
|
||||
}
|
||||
}
|
||||
|
||||
return resolver.cast();
|
||||
return resolver.cast()
|
||||
}
|
||||
|
||||
return LazyOptional.empty();
|
||||
return LazyOptional.empty()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_);
|
||||
|
||||
if (stack.getTag() != null) {
|
||||
var uuid = stack.getTag().getLongArray("uuid");
|
||||
|
||||
if (uuid.length == 2) {
|
||||
p_41423_.add(new TextComponent(new UUID(uuid[0], uuid[1]).toString()).withStyle(ChatFormatting.GRAY));
|
||||
override fun appendHoverText(
|
||||
stack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
p_41423_: MutableList<Component>,
|
||||
p_41424_: TooltipFlag
|
||||
) {
|
||||
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_)
|
||||
if (stack.tag != null) {
|
||||
val uuid = stack.tag!!.getLongArray("uuid")
|
||||
if (uuid.size == 2) {
|
||||
p_41423_.add(TextComponent(UUID(uuid[0], uuid[1]).toString()).withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
return new DriveCapability(stack);
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
return DriveCapability(stack)
|
||||
}
|
||||
|
||||
public static class FilterSettings {
|
||||
public static final int MAX_FILTERS = 12;
|
||||
public final ItemStack[] items = new ItemStack[MAX_FILTERS];
|
||||
public boolean match_nbt;
|
||||
public boolean match_tag;
|
||||
public boolean blacklist;
|
||||
class FilterSettings() {
|
||||
@JvmField
|
||||
val items = Array<ItemStack>(MAX_FILTERS) { ItemStack.EMPTY }
|
||||
|
||||
public FilterSettings() {
|
||||
Arrays.fill(items, ItemStack.EMPTY);
|
||||
}
|
||||
@JvmField
|
||||
var matchNbt = false
|
||||
|
||||
public FilterSettings(CompoundTag tag) {
|
||||
this();
|
||||
@JvmField
|
||||
var matchTag = false
|
||||
|
||||
var list = tag.getList("filter", Tag.TAG_COMPOUND);
|
||||
var i = 0;
|
||||
@JvmField
|
||||
var isBlacklist = false
|
||||
|
||||
for (var get_tag : list) {
|
||||
if (get_tag instanceof CompoundTag compound) {
|
||||
items[i++] = ItemStack.of(compound);
|
||||
constructor(tag: CompoundTag) : this() {
|
||||
val list = tag.getList("filter", Tag.TAG_COMPOUND.toInt())
|
||||
var i = 0
|
||||
|
||||
for (tag in list) {
|
||||
if (tag is CompoundTag) {
|
||||
items[i++] = ItemStack.of(tag)
|
||||
}
|
||||
}
|
||||
|
||||
match_nbt = tag.getBoolean("match_nbt");
|
||||
match_tag = tag.getBoolean("match_tag");
|
||||
blacklist = tag.getBoolean("blacklist");
|
||||
matchNbt = tag.getBoolean("match_nbt")
|
||||
matchTag = tag.getBoolean("match_tag")
|
||||
isBlacklist = tag.getBoolean("blacklist")
|
||||
}
|
||||
|
||||
public void serializeNBT(CompoundTag compound) {
|
||||
var list = new ListTag();
|
||||
fun serializeNBT(compound: CompoundTag) {
|
||||
val list = ListTag()
|
||||
|
||||
for (int i = 0; i < MAX_FILTERS; i++) {
|
||||
list.add(items[i].serializeNBT());
|
||||
for (i in 0 until MAX_FILTERS) {
|
||||
list.add(items[i].serializeNBT())
|
||||
}
|
||||
|
||||
compound.put("filter", list);
|
||||
compound.putBoolean("match_nbt", match_nbt);
|
||||
compound.putBoolean("match_tag", match_tag);
|
||||
compound.putBoolean("blacklist", blacklist);
|
||||
compound["filter"] = list
|
||||
compound["match_nbt"] = matchNbt
|
||||
compound["match_tag"] = matchTag
|
||||
compound["blacklist"] = isBlacklist
|
||||
}
|
||||
|
||||
public void serializeNBT(ItemStack drive) {
|
||||
serializeNBT(drive.getOrCreateTag());
|
||||
fun serializeNBT(drive: ItemStack) {
|
||||
serializeNBT(drive.orCreateTag)
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack stack) {
|
||||
if (blacklist) {
|
||||
for (var item : items) {
|
||||
if (!match_nbt && ItemStack.isSame(item, stack)) {
|
||||
return false;
|
||||
fun matches(stack: ItemStack): Boolean {
|
||||
if (isBlacklist) {
|
||||
for (item in items) {
|
||||
if (!matchNbt && ItemStack.isSame(item, stack)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (match_tag) {
|
||||
var this_tags = item.getItem().getTags();
|
||||
var stack_tatgs = stack.getItem().getTags();
|
||||
if (matchTag) {
|
||||
val thisTags = item.item.tags
|
||||
val stackTatgs = stack.item.tags
|
||||
|
||||
for (var tag1 : this_tags) {
|
||||
if (stack_tatgs.contains(tag1)) {
|
||||
return false;
|
||||
for (tag1 in thisTags) {
|
||||
if (stackTatgs.contains(tag1)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match_nbt && ItemStack.isSameItemSameTags(item, stack)) {
|
||||
return false;
|
||||
if (matchNbt && ItemStack.isSameItemSameTags(item, stack)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
} else {
|
||||
for (var item : items) {
|
||||
boolean same = ItemStack.isSame(item, stack);
|
||||
for (item in items) {
|
||||
var same = ItemStack.isSame(item, stack)
|
||||
|
||||
if (!same && match_tag) {
|
||||
var this_tags = item.getItem().getTags();
|
||||
var stack_tatgs = stack.getItem().getTags();
|
||||
if (!same && matchTag) {
|
||||
val thisTags = item.item.tags
|
||||
val stackTatgs = stack.item.tags
|
||||
|
||||
for (var tag1 : this_tags) {
|
||||
if (stack_tatgs.contains(tag1)) {
|
||||
same = true;
|
||||
break;
|
||||
for (tag1 in thisTags) {
|
||||
if (stackTatgs.contains(tag1)) {
|
||||
same = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match_nbt) {
|
||||
if (matchNbt) {
|
||||
if (same && ItemStack.tagMatches(item, stack)) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
if (same) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MAX_FILTERS = 12
|
||||
}
|
||||
}
|
||||
|
||||
fun getFilterSettings(drive: ItemStack): FilterSettings {
|
||||
return FilterSettings(drive.orCreateTag)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
companion object {
|
||||
@SubscribeEvent
|
||||
fun onPickupEvent(event: EntityItemPickupEvent) {
|
||||
if (event.item.owner != null && event.item.owner != event.player.uuid && event.item.age < 200) {
|
||||
return
|
||||
}
|
||||
|
||||
var amount = event.item.item.count
|
||||
val item = event.item.item.item
|
||||
|
||||
for (stack in event.player.inventory.items) {
|
||||
val drive = stack.item
|
||||
|
||||
if (drive is ItemPortableCondensationDrive) {
|
||||
var doBreak = false
|
||||
|
||||
stack.getCapability(MatteryCapability.DRIVE).ifPresent {
|
||||
val filter = drive.getFilterSettings(stack)
|
||||
|
||||
if (filter.matches(event.item.item)) {
|
||||
val copy = event.item.item.copy()
|
||||
val remaining = (it as ItemMatteryDrive).insertObject(event.item.item, false)
|
||||
|
||||
if (remaining.count == event.item.item.count) {
|
||||
return@ifPresent
|
||||
}
|
||||
|
||||
copy.count -= remaining.count
|
||||
event.isCanceled = true
|
||||
ForgeEventFactory.firePlayerItemPickupEvent(event.player, event.item, copy)
|
||||
|
||||
if (remaining.count > 0) {
|
||||
event.item.item.count = remaining.count
|
||||
event.player.take(event.item, amount - remaining.count)
|
||||
|
||||
event.player.awardStat(Stats.ITEM_PICKED_UP.get(item), amount - remaining.count)
|
||||
event.player.onItemPickup(event.item)
|
||||
|
||||
amount = remaining.count
|
||||
} else {
|
||||
event.player.take(event.item, amount)
|
||||
|
||||
event.player.awardStat(Stats.ITEM_PICKED_UP.get(item), amount)
|
||||
event.player.onItemPickup(event.item)
|
||||
|
||||
event.item.discard()
|
||||
doBreak = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FilterSettings getFilterSettings(ItemStack drive) {
|
||||
return new FilterSettings(drive.getOrCreateTag());
|
||||
if (doBreak) return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user