generated from NeoForgeMDKs/MDK-1.21.1-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/net/enderio/capacitoradditions/component/ModDataComponents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |