Skip to content

Commit

Permalink
capacitor now works in machine
Browse files Browse the repository at this point in the history
  • Loading branch information
lustig7 committed Dec 30, 2024
1 parent 3597ce1 commit e351ff3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 17 deletions.
25 changes: 25 additions & 0 deletions src/main/java/item/Capacitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package item;

import com.enderio.base.api.capacitor.*;

import java.util.Map;

public class Capacitor {
public static final CapacitorData ALLTHEMODIUM_CAPACITOR_DATA = new CapacitorData(
3.5f, // Base value
Map.of(
)
);
public static final CapacitorData VIBRANIUM_CAPACITOR_DATA = new CapacitorData(
4.0f,
Map.of(
)
);


public static final CapacitorData UNOBTAINIUM_CAPACITOR_DATA = new CapacitorData(
4.5f, // Base value
Map.of(
)
);
}
43 changes: 29 additions & 14 deletions src/main/java/item/CustomCapacitor.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
package item;

import com.enderio.base.api.capacitor.CapacitorData;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import net.enderio.capacitoradditions.component.ModDataComponents;

public class CustomCapacitor extends Item implements CapacitorData {
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.TooltipFlag;

public CustomCapacitor(Item.Properties properties) {
import java.util.List;

public class CustomCapacitor extends Item {
private final DataComponentType<CapacitorData> dataType;
private final CapacitorData capacitorData;

public CustomCapacitor(Properties properties, DataComponentType<CapacitorData> dataType, CapacitorData capacitorData) {
super(properties);
this.dataType = dataType;
this.capacitorData = capacitorData;
}

@Override
public int getBaseEnergy(ItemStack stack) {
// Implement the method to return the base energy of the capacitor
return 1000; // Example value

@NotNull
public CapacitorData getCapacitorData(@NotNull ItemStack stack) {
// Return the capacitor data tied to this item
return capacitorData;
}

@Override
public int getMaxEnergy(ItemStack stack) {
// Implement the method to return the maximum energy of the capacitor
return 10000; // Example value
public DataComponentType<CapacitorData> getDataType() {
return dataType;
}

@Override
public int getEnergyTransferRate(ItemStack stack) {
// Implement the method to return the energy transfer rate of the capacitor
return 100; // Example value
public void verifyComponentsAfterLoad(ItemStack stack) {
if(stack.get(ModDataComponents.CAPACITOR_DATA_TYPE) == null) {
stack.set(ModDataComponents.CAPACITOR_DATA_TYPE, getCapacitorData(stack));
}

}
}


}
30 changes: 28 additions & 2 deletions src/main/java/item/Items.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package item;

import com.enderio.base.api.capacitor.CapacitorData;
import com.enderio.base.api.registry.EnderIORegistries;
import com.enderio.regilite.holder.RegiliteItem;
import net.enderio.capacitoradditions.CapacitorAdditions;
import net.enderio.capacitoradditions.component.ModDataComponents;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.Registries;
Expand All @@ -13,14 +15,38 @@

import java.util.function.Supplier;

import static net.enderio.capacitoradditions.component.ModDataComponents.CAPACITOR_DATA_TYPE;


public class Items {

public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(CapacitorAdditions.MOD_ID);


/*public static Supplier<DataComponentType<CapacitorData>> CAPACITOR_DATA_TYPE = DATA_COMPONENT_TYPES.registerComponentType("capacitor_data",
builder -> builder.persistent(CapacitorData.CODEC).networkSynchronized(CapacitorData.STREAM_CODEC));*/


public static final DeferredItem<Item> vibranium_capacitor = ITEMS.register(
"vibranium_capacitor",
() -> new Item(new Item.Properties()));
() -> new CustomCapacitor(new Item.Properties(), CAPACITOR_DATA_TYPE.get(), Capacitor.VIBRANIUM_CAPACITOR_DATA)
);

public static final DeferredItem<Item> allthemodium_capacitor = ITEMS.register(
"allthemodium_capacitor",
() -> new CustomCapacitor(new Item.Properties(), CAPACITOR_DATA_TYPE.get(), Capacitor.ALLTHEMODIUM_CAPACITOR_DATA)
);

public static final DeferredItem<Item> unobtainium_capacitor = ITEMS.register(
"unobtainium_capacitor",
() -> new CustomCapacitor(new Item.Properties(), CAPACITOR_DATA_TYPE.get(), Capacitor.UNOBTAINIUM_CAPACITOR_DATA)
);



/*public static final DeferredItem<Item> vibranium_capacitor = ITEMS.register(
"vibranium_capacitor",
() -> new CustomCapacitor(new Item.Properties()));
public static final DeferredItem<Item> allthemodium_capacitor = ITEMS.register(
Expand All @@ -29,7 +55,7 @@ public class Items {
public static final DeferredItem<Item> unobtainium_capacitor = ITEMS.register(
"unobtainium_capacitor",
() -> new Item(new Item.Properties()));
() -> new CustomCapacitor(new Item.Properties()));*/



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.enderio.base.api.capacitor.CapacitorData;
import com.mojang.logging.LogUtils;
import item.Items;
import net.enderio.capacitoradditions.component.ModDataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
Expand Down Expand Up @@ -56,7 +57,7 @@ public CapacitorAdditions(IEventBus modEventBus, ModContainer modContainer)
Items.register(modEventBus);

CREATIVE_MODE_TABS.register(modEventBus);

ModDataComponents.register(modEventBus);



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.enderio.capacitoradditions.component;

import com.enderio.base.api.capacitor.CapacitorData;
import item.CustomCapacitor;
import net.minecraft.core.component.DataComponentType;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.function.UnaryOperator;

public class ModDataComponents {

private static final DeferredRegister.DataComponents DATA_COMPONENT_TYPES = DeferredRegister.createDataComponents("enderio");

public static final DeferredHolder<DataComponentType<?>, DataComponentType<CapacitorData>> CAPACITOR_DATA_TYPE = register("capacitor_data",
builder -> builder.persistent(CapacitorData.CODEC));

private static <T>DeferredHolder<DataComponentType<?>, DataComponentType<T>> register(String name,
UnaryOperator<DataComponentType.Builder<T>> builderOperator) {
return DATA_COMPONENT_TYPES.register(name, () -> builderOperator.apply(DataComponentType.builder()).build());
}


public static void register(IEventBus eventBus) {
DATA_COMPONENT_TYPES.register(eventBus);
}
}

0 comments on commit e351ff3

Please sign in to comment.