-
Notifications
You must be signed in to change notification settings - Fork 11
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
9 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...n/src/main/java/org/valkyrienskies/tournament/mixin/level/MixinAbstractCauldronBlock.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,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); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/kotlin/org/valkyrienskies/tournament/CauldronRecipes.kt
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,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 | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
common/src/main/kotlin/org/valkyrienskies/tournament/util/Heat.kt
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,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
31
common/src/main/kotlin/org/valkyrienskies/tournament/util/TierD.kt
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,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 | ||
} |
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
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/vs_tournament/models/item/phygold_sword.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "vs_tournament:item/phygold_sword" | ||
} | ||
} |
Binary file added
BIN
+622 Bytes
common/src/main/resources/assets/vs_tournament/textures/item/phygold_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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