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