Skip to content

Commit

Permalink
Start porting the mod, some work to do
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Oct 27, 2024
1 parent 9cc2666 commit 8acbf1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
19 changes: 12 additions & 7 deletions reference/latest/src/main/java/com/example/docs/item/ModItems.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.example.docs.item;

import net.fabricmc.fabric.api.registry.FuelRegistryEvents;

import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.FuelRegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.equipment.EquipmentType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
Expand All @@ -18,7 +22,6 @@
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistry;

import com.example.docs.FabricDocsReference;
import com.example.docs.component.ModComponents;
Expand All @@ -32,14 +35,14 @@ public class ModItems {
// :::1

// :::6
public static final Item GUIDITE_HELMET = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.HELMET, new Item.Settings().maxDamage(ArmorItem.Type.HELMET.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_helmet");
public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.CHESTPLATE, new Item.Settings().maxDamage(ArmorItem.Type.CHESTPLATE.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_chestplate");
public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.LEGGINGS, new Item.Settings().maxDamage(ArmorItem.Type.LEGGINGS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_leggings");
public static final Item GUIDITE_BOOTS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.BOOTS, new Item.Settings().maxDamage(ArmorItem.Type.BOOTS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_boots");
public static final Item GUIDITE_HELMET = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.HELMET, new Item.Settings().maxDamage(EquipmentType.HELMET.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_helmet");
public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.CHESTPLATE, new Item.Settings().maxDamage(EquipmentType.CHESTPLATE.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_chestplate");
public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.LEGGINGS, new Item.Settings().maxDamage(EquipmentType.LEGGINGS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_leggings");
public static final Item GUIDITE_BOOTS = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.BOOTS, new Item.Settings().maxDamage(EquipmentType.BOOTS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_boots");
// :::6
public static final Item LIGHTNING_STICK = register(new LightningStick(new Item.Settings()), "lightning_stick");
// :::7
public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, new Item.Settings()), "guidite_sword");
public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, 1.5F, 1F, new Item.Settings()), "guidite_sword");
// :::7
// :::_13
public static final Item COUNTER = register(new CounterItem(
Expand Down Expand Up @@ -141,7 +144,9 @@ public static void initialize() {
// Add the suspicious substance to the flammable block registry with a burn time of 30 seconds.
// Remember, Minecraft deals with logical based-time using ticks.
// 20 ticks = 1 second.
FuelRegistry.INSTANCE.add(ModItems.GUIDITE_SWORD, 30 * 20);
FuelRegistryEvents.BUILD.register((builder, context) -> {
builder.add(ModItems.GUIDITE_SWORD, 30 * 20);
});
// :::_11
// :::3
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

import com.example.docs.component.ModComponents;
Expand All @@ -24,20 +24,20 @@ public CounterItem(Settings settings) {

@Override
//::2
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
public ActionResult use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);

// Don't do anything on the client
if (world.isClient()) {
return TypedActionResult.success(stack);
return ActionResult.SUCCESS;
}

// Read the current count and increase it by one
int count = stack.getOrDefault(ModComponents.CLICK_COUNT_COMPONENT, 0);
stack.set(ModComponents.CLICK_COUNT_COMPONENT, ++count);

// Return the original stack
return TypedActionResult.success(stack);
return ActionResult.SUCCESS;
}

//::2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand All @@ -24,11 +24,11 @@ public LightningStick(Settings settings) {
// :::1
// :::2
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
public ActionResult use(World world, PlayerEntity user, Hand hand) {
// Ensure we don't spawn the lightning only on the client.
// This is to prevent desync.
if (world.isClient) {
return TypedActionResult.pass(user.getStackInHand(hand));
return ActionResult.PASS;
}

BlockPos frontOfPlayer = user.getBlockPos().offset(user.getHorizontalFacing(), 10);
Expand All @@ -40,7 +40,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han

// Nothing has changed to the item stack,
// so we just return it how it was.
return TypedActionResult.success(user.getStackInHand(hand));
return ActionResult.SUCCESS;
}

// :::2
Expand Down

0 comments on commit 8acbf1d

Please sign in to comment.