Skip to content

Commit

Permalink
v1.3 - The woodening
Browse files Browse the repository at this point in the history
  • Loading branch information
DakotaPride committed Nov 4, 2023
1 parent 2d157e9 commit 2230dcb
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.dakotapride.garnished.entity;

import net.minecraft.world.entity.vehicle.Boat;

public class GarnishedBoatTypes {
static {
Boat.Type.values();
}

public static Boat.Type NUT;
}
11 changes: 11 additions & 0 deletions src/main/java/net/dakotapride/garnished/item/wood/NutBoatItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.dakotapride.garnished.item.wood;

import net.dakotapride.garnished.entity.GarnishedBoatTypes;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.item.BoatItem;

public class NutBoatItem extends BoatItem {
public NutBoatItem(Properties properties) {
super(false, GarnishedBoatTypes.NUT, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.dakotapride.garnished.item.wood;

import net.dakotapride.garnished.entity.GarnishedBoatTypes;
import net.minecraft.world.item.BoatItem;

public class NutChestBoatItem extends BoatItem {
public NutChestBoatItem(Properties properties) {
super(true, GarnishedBoatTypes.NUT, properties);
}
}
27 changes: 27 additions & 0 deletions src/main/java/net/dakotapride/garnished/mixin/BoatMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.dakotapride.garnished.mixin;

import net.dakotapride.garnished.entity.GarnishedBoatTypes;
import net.dakotapride.garnished.registry.GarnishedItems;
import net.minecraft.world.entity.vehicle.Boat;

import net.minecraft.world.item.Item;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Boat.class)
public class BoatMixin {

//CREDIT TO nyuppo/fabric-boat-example ON GITHUB

@Inject(method = "getDropItem", at = @At("RETURN"), cancellable = true)
public void wilderWild$getModdedBoats(CallbackInfoReturnable<Item> info) {
var boat = Boat.class.cast(this);
if (boat.getVariant() == GarnishedBoatTypes.NUT) {
info.setReturnValue(GarnishedItems.NUT_BOAT.get());
}
}

}
54 changes: 54 additions & 0 deletions src/main/java/net/dakotapride/garnished/mixin/BoatTypeMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.dakotapride.garnished.mixin;

import net.dakotapride.garnished.entity.GarnishedBoatTypes;
import net.dakotapride.garnished.registry.GarnishedBlocks;
import net.minecraft.world.entity.vehicle.Boat;

import net.minecraft.world.level.block.Block;

import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.Arrays;

@Mixin(Boat.Type.class)
public class BoatTypeMixin {

//CREDIT TO nyuppo/fabric-boat-example ON GITHUB

@SuppressWarnings("ShadowTarget")
@Final
@Shadow
@Mutable
private static Boat.Type[] $VALUES;

@SuppressWarnings("InvokerTarget")
@Invoker("<init>")
private static Boat.Type newType(String internalName, int internalId, Block baseBlock, String name) {
throw new AssertionError();
}

@Inject(method = "<clinit>", at = @At(value = "FIELD",
opcode = Opcodes.PUTSTATIC,
target = "Lnet/minecraft/world/entity/vehicle/Boat$Type;$VALUES:[Lnet/minecraft/world/entity/vehicle/Boat$Type;",
shift = At.Shift.AFTER))
private static void wilderWild$addCustomBoatType(CallbackInfo info) {
var types = new ArrayList<>(Arrays.asList($VALUES));
var last = types.get(types.size() - 1);

var nut = newType("NUT", last.ordinal() + 1, GarnishedBlocks.NUT_PLANKS.get(), "nut");
GarnishedBoatTypes.NUT = nut;
types.add(nut);

$VALUES = types.toArray(new Boat.Type[0]);
}

}
27 changes: 27 additions & 0 deletions src/main/java/net/dakotapride/garnished/mixin/ChestBoatMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.dakotapride.garnished.mixin;

import net.dakotapride.garnished.entity.GarnishedBoatTypes;
import net.dakotapride.garnished.registry.GarnishedItems;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.entity.vehicle.ChestBoat;
import net.minecraft.world.item.Item;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChestBoat.class)
public class ChestBoatMixin {

//CREDIT TO nyuppo/fabric-boat-example ON GITHUB

@Inject(method = "getDropItem", at = @At("RETURN"), cancellable = true)
public void wilderWild$getModdedBoats(CallbackInfoReturnable<Item> info) {
var boat = Boat.class.cast(this);
if (boat.getVariant() == GarnishedBoatTypes.NUT) {
info.setReturnValue(GarnishedItems.NUT_CHEST_BOAT.get());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ private static Potion vanillaPotion(String key, Potion potion) {
return Registry.register(BuiltInRegistries.POTION, new ResourceLocation(key), potion);
}

public static void setRegister() {

}
public static void setRegister() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.dakotapride.garnished.item.hatchet.tier.NetheriteHatchetToolItem;
import net.dakotapride.garnished.item.hatchet.tier.StoneHatchetToolItem;
import net.dakotapride.garnished.item.hatchet.tier.WoodenHatchetToolItem;
import net.dakotapride.garnished.item.wood.NutBoatItem;
import net.dakotapride.garnished.item.wood.NutChestBoatItem;
import net.dakotapride.garnished.item.wood.NutSignItem;
import net.dakotapride.garnished.item.wood.SepiaSignItem;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -427,7 +429,10 @@ public class GarnishedItems {
public static final ItemEntry<NutSignItem.Hanging> NUT_HANGING_SIGN =
REGISTRATE.item("nut_hanging_sign", NutSignItem.Hanging::new).register();

// v1.3
public static final ItemEntry<NutBoatItem> NUT_BOAT =
REGISTRATE.item("nut_boat", NutBoatItem::new).register();
public static final ItemEntry<NutChestBoatItem> NUT_CHEST_BOAT =
REGISTRATE.item("nut_chest_boat", NutChestBoatItem::new).register();

// Farmer's Delight Items
public static final ItemEntry<PecanPieSliceFoodItem> PECAN_PIE_SLICE =
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/garnished.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"package": "net.dakotapride.garnished.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"BoatMixin",
"BoatTypeMixin",
"ChestBoatMixin",
"EnderManMixin",
"ItemStackMixin",
"LivingEntityMixin"
Expand Down

0 comments on commit 2230dcb

Please sign in to comment.