Skip to content

Commit

Permalink
phygold sword
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 committed Aug 24, 2024
1 parent c0ca31a commit 68cbed1
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<InteractionResult> cir) {
if (hand == InteractionHand.OFF_HAND) {
var items = new HashMap<Item, Integer>();

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<Entity>();
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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Item, Int>.craft(need: Map<Item, Int>): 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<Item, Int>, 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -21,9 +30,13 @@ object TournamentItems {
lateinit var TOOL_DELETEWAND : RegistrySupplier<ShipDeleteWandItem>
lateinit var UPGRADE_THRUSTER : RegistrySupplier<Item>
lateinit var GIFT_BAG : RegistrySupplier<GiftBagItem>
lateinit var INGOT_PHYNITE : RegistrySupplier<Item>
lateinit var PHYGOLD_SWORD : RegistrySupplier<SwordItem>

lateinit var TAB: CreativeModeTab

lateinit var TIER_PHYGOLD : Tier

fun register() {
ROPE = ITEMS.register("rope", ::RopeItem)
TOOL_PULSEGUN = ITEMS.register("pulse_gun", ::PulseGunItem)
Expand All @@ -46,14 +59,20 @@ object TournamentItems {
Item(Properties().stacksTo(64).tab(TAB))
}

ITEMS.register("ingot_phynite") {
INGOT_PHYNITE = ITEMS.register("ingot_phynite") {
Item(Properties().stacksTo(64).tab(TAB))
}

ITEMS.register("physics_shard") {
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:
Expand Down
24 changes: 24 additions & 0 deletions common/src/main/kotlin/org/valkyrienskies/tournament/util/Heat.kt
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions common/src/main/kotlin/org/valkyrienskies/tournament/util/TierD.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "vs_tournament:item/phygold_sword"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions common/src/main/resources/vs_tournament-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"minVersion": "0.8",
"mixins": [
"advancements.MixinCriteriaTriggers",
"level.MixinAbstractCauldronBlock",
"level.MixinBiomeGenerationSettingsBuilder",
"level.MixinServerLevel"
]
Expand Down

0 comments on commit 68cbed1

Please sign in to comment.