diff --git a/common/src/main/java/org/valkyrienskies/tournament/mixin/level/MixinAbstractCauldronBlock.java b/common/src/main/java/org/valkyrienskies/tournament/mixin/level/MixinAbstractCauldronBlock.java new file mode 100644 index 0000000..9e2b622 --- /dev/null +++ b/common/src/main/java/org/valkyrienskies/tournament/mixin/level/MixinAbstractCauldronBlock.java @@ -0,0 +1,104 @@ +package org.valkyrienskies.tournament.mixin.level; + +import kotlin.Unit; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.AbstractCauldronBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +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; +import org.valkyrienskies.tournament.CauldronRecipes; +import org.valkyrienskies.tournament.ShaftsKt; +import org.valkyrienskies.tournament.util.HeatKt; + +import java.util.ArrayList; +import java.util.HashMap; + +@Mixin(AbstractCauldronBlock.class) +public abstract class MixinAbstractCauldronBlock { + @Inject(at = @At("HEAD"), method = "use", cancellable = true) + public void use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable cir) { + if (hand == InteractionHand.OFF_HAND) { + var items = new HashMap(); + + var es = level.getEntities(null, AABB.ofSize(Vec3.atCenterOf(pos), 1, 1, 1)); + for (Entity e : es) { + if (e instanceof ItemEntity ie) { + var stack = ie.getItem(); + var old = 0; + if (items.containsKey(stack.getItem())) { + old = items.get(stack.getItem()); + } + + items.put(stack.getItem(), old + stack.getCount()); + } + } + + int heat = 0; + for (BlockPos p : ShaftsKt.neighborBlocks(pos)) { + heat += HeatKt.getHeat(level.getBlockState(p)); + } + + var clicked = player.getMainHandItem(); + + var env = new CauldronRecipes.Env(heat); + + var oldItems = new HashMap<>(items); + + boolean once = false; + while (CauldronRecipes.craftOnce(clicked, items, (ItemStack i) -> { + Block.popResource(level, pos, i); + return Unit.INSTANCE; + }, env)) { + once = true; + + oldItems.forEach((entry, count) -> { + int neww = items.get(entry); + if (neww < count) { + var removed = count - neww; + + var toKill = new ArrayList(); + for (var e : es) { + if (e instanceof ItemEntity ie) { + var stack = ie.getItem(); + + if (stack.getItem() == entry) { + int a = stack.getCount() - removed; + if (a < 0) a = 0; + + stack.setCount(a); + if (a == 0) { + toKill.add(e); + } + } + } + } + + for (var e : toKill) { + e.kill(); + } + } + }); + oldItems = new HashMap<>(items); + } + + if (once) { + cir.setReturnValue(InteractionResult.CONSUME_PARTIAL); + } + } + } +} diff --git a/common/src/main/kotlin/org/valkyrienskies/tournament/CauldronRecipes.kt b/common/src/main/kotlin/org/valkyrienskies/tournament/CauldronRecipes.kt new file mode 100644 index 0000000..0338a4a --- /dev/null +++ b/common/src/main/kotlin/org/valkyrienskies/tournament/CauldronRecipes.kt @@ -0,0 +1,30 @@ +package org.valkyrienskies.tournament + +import net.minecraft.world.item.Item +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.Items + +object CauldronRecipes { + data class Env(var heat: Int) + + fun MutableMap.craft(need: Map): Boolean { + if (need.all { this[it.key]?.let { v -> v >= it.value } == true }) { + need.forEach { (k, v) -> + this.compute(k) { _, old -> old!! - v } + } + return true + } + return false + } + + @JvmStatic + fun craftOnce(main: ItemStack, sources: MutableMap, output: (ItemStack) -> Unit, env: Env): Boolean { + if (main.item == Items.GOLDEN_SWORD && env.heat >= 8 && sources.craft(mapOf(TournamentItems.INGOT_PHYNITE.get() to 4))) { + main.count -- + output(ItemStack(TournamentItems.PHYGOLD_SWORD.get(), 1)) + return true + } + + return false + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/org/valkyrienskies/tournament/TournamentItems.kt b/common/src/main/kotlin/org/valkyrienskies/tournament/TournamentItems.kt index b334c5b..3f3f811 100644 --- a/common/src/main/kotlin/org/valkyrienskies/tournament/TournamentItems.kt +++ b/common/src/main/kotlin/org/valkyrienskies/tournament/TournamentItems.kt @@ -4,11 +4,20 @@ import net.minecraft.core.Registry import net.minecraft.world.item.CreativeModeTab import net.minecraft.world.item.Item import net.minecraft.world.item.Item.Properties -import org.valkyrienskies.tournament.items.* +import net.minecraft.world.item.Items +import net.minecraft.world.item.SwordItem +import net.minecraft.world.item.Tier +import net.minecraft.world.item.crafting.Ingredient +import net.minecraft.world.level.ItemLike +import org.valkyrienskies.tournament.items.GiftBagItem +import org.valkyrienskies.tournament.items.PulseGunItem +import org.valkyrienskies.tournament.items.RopeItem +import org.valkyrienskies.tournament.items.ShipDeleteWandItem import org.valkyrienskies.tournament.items.old.OldItem import org.valkyrienskies.tournament.items.old.UpdateItem import org.valkyrienskies.tournament.registry.DeferredRegister import org.valkyrienskies.tournament.registry.RegistrySupplier +import org.valkyrienskies.tournament.util.TierD @Suppress("unused") @@ -21,9 +30,13 @@ object TournamentItems { lateinit var TOOL_DELETEWAND : RegistrySupplier lateinit var UPGRADE_THRUSTER : RegistrySupplier lateinit var GIFT_BAG : RegistrySupplier + lateinit var INGOT_PHYNITE : RegistrySupplier + lateinit var PHYGOLD_SWORD : RegistrySupplier lateinit var TAB: CreativeModeTab + lateinit var TIER_PHYGOLD : Tier + fun register() { ROPE = ITEMS.register("rope", ::RopeItem) TOOL_PULSEGUN = ITEMS.register("pulse_gun", ::PulseGunItem) @@ -46,7 +59,7 @@ object TournamentItems { Item(Properties().stacksTo(64).tab(TAB)) } - ITEMS.register("ingot_phynite") { + INGOT_PHYNITE = ITEMS.register("ingot_phynite") { Item(Properties().stacksTo(64).tab(TAB)) } @@ -54,6 +67,12 @@ object TournamentItems { Item(Properties().stacksTo(64).tab(TAB)) } + TIER_PHYGOLD = TierD(3, 1561, 8.0f, 3.5f, 20, Ingredient.of(INGOT_PHYNITE.get())) + + PHYGOLD_SWORD = ITEMS.register("phygold_sword") { + SwordItem(TIER_PHYGOLD, 3, -2.4f, Properties().tab(TAB)) + } + fuelItems.forEach { ITEMS.register(it.first) { Item(Properties().stacksTo(64).tab(TAB)) } } // old: diff --git a/common/src/main/kotlin/org/valkyrienskies/tournament/util/Heat.kt b/common/src/main/kotlin/org/valkyrienskies/tournament/util/Heat.kt new file mode 100644 index 0000000..dbaf04e --- /dev/null +++ b/common/src/main/kotlin/org/valkyrienskies/tournament/util/Heat.kt @@ -0,0 +1,24 @@ +package org.valkyrienskies.tournament.util + +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.CampfireBlock +import net.minecraft.world.level.block.FireBlock +import net.minecraft.world.level.block.state.BlockState + +fun BlockState.getHeat(): Int = + when (block) { + Blocks.ICE -> -2 + + Blocks.SNOW, + Blocks.SNOW_BLOCK, + Blocks.POWDER_SNOW, + Blocks.POWDER_SNOW_CAULDRON -> -1 + Blocks.LAVA, + Blocks.LAVA_CAULDRON -> 2 + + is FireBlock -> 1 + + is CampfireBlock -> if (hasProperty(CampfireBlock.LIT) && getValue(CampfireBlock.LIT)) 1 else 0 + + else -> 0 + } \ No newline at end of file diff --git a/common/src/main/kotlin/org/valkyrienskies/tournament/util/TierD.kt b/common/src/main/kotlin/org/valkyrienskies/tournament/util/TierD.kt new file mode 100644 index 0000000..eb1eec6 --- /dev/null +++ b/common/src/main/kotlin/org/valkyrienskies/tournament/util/TierD.kt @@ -0,0 +1,31 @@ +package org.valkyrienskies.tournament.util + +import net.minecraft.world.item.Tier +import net.minecraft.world.item.crafting.Ingredient + +data class TierD( + private val level: Int, + private val uses: Int, + private val speed: Float, + private val attackDamageBonus: Float, + private val enchantmentValue: Int, + private val repairIngredient: Ingredient, +): Tier { + override fun getUses(): Int = + uses + + override fun getSpeed(): Float = + speed + + override fun getAttackDamageBonus(): Float = + attackDamageBonus + + override fun getLevel(): Int = + level + + override fun getEnchantmentValue(): Int = + enchantmentValue + + override fun getRepairIngredient(): Ingredient = + repairIngredient +} \ No newline at end of file diff --git a/common/src/main/resources/assets/vs_tournament/lang/en_us.json b/common/src/main/resources/assets/vs_tournament/lang/en_us.json index 4d8a0d1..2fea966 100644 --- a/common/src/main/resources/assets/vs_tournament/lang/en_us.json +++ b/common/src/main/resources/assets/vs_tournament/lang/en_us.json @@ -42,6 +42,7 @@ "item.vs_tournament.raw_phynite": "Raw Phynite", "item.vs_tournament.ingot_phynite": "Phynite Ingot", "item.vs_tournament.physics_shard": "Physics Shard", + "item.vs_tournament.phygold_sword": "PhyGoldâ„¢ Sword", "item.vs_tournament.basic_fuel_powder": "Basic Fuel Powder", "item.vs_tournament.basic_fuel_paste": "Basic Fuel Paste", diff --git a/common/src/main/resources/assets/vs_tournament/models/item/phygold_sword.json b/common/src/main/resources/assets/vs_tournament/models/item/phygold_sword.json new file mode 100644 index 0000000..9771166 --- /dev/null +++ b/common/src/main/resources/assets/vs_tournament/models/item/phygold_sword.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "vs_tournament:item/phygold_sword" + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/vs_tournament/textures/item/phygold_sword.png b/common/src/main/resources/assets/vs_tournament/textures/item/phygold_sword.png new file mode 100644 index 0000000..756ffd6 Binary files /dev/null and b/common/src/main/resources/assets/vs_tournament/textures/item/phygold_sword.png differ diff --git a/common/src/main/resources/vs_tournament-common.mixins.json b/common/src/main/resources/vs_tournament-common.mixins.json index aa0b975..74b2473 100644 --- a/common/src/main/resources/vs_tournament-common.mixins.json +++ b/common/src/main/resources/vs_tournament-common.mixins.json @@ -14,6 +14,7 @@ "minVersion": "0.8", "mixins": [ "advancements.MixinCriteriaTriggers", + "level.MixinAbstractCauldronBlock", "level.MixinBiomeGenerationSettingsBuilder", "level.MixinServerLevel" ]