we do a little trolling
This commit is contained in:
parent
bc8a52acd4
commit
83502eb240
@ -1,19 +1,39 @@
|
||||
package ru.dbotthepony.mc.otm.datagen.recipes
|
||||
|
||||
import net.minecraft.data.recipes.FinishedRecipe
|
||||
import net.minecraft.data.recipes.RecipeCategory
|
||||
import net.minecraft.data.recipes.RecipeOutput
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder
|
||||
import net.minecraft.tags.TagKey
|
||||
import net.minecraft.world.item.DyeColor
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.Items
|
||||
import net.minecraft.world.item.crafting.Ingredient
|
||||
import net.minecraft.world.level.ItemLike
|
||||
import net.minecraftforge.common.Tags
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.datagen.modLocation
|
||||
import ru.dbotthepony.mc.otm.registry.MItemTags
|
||||
import ru.dbotthepony.mc.otm.registry.MItems
|
||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
||||
import java.util.function.Consumer
|
||||
|
||||
fun hammerRecipe(output: ItemLike, input: ItemLike, consumer: RecipeOutput) {
|
||||
ShapelessRecipeBuilder(RecipeCategory.MISC, output, 1)
|
||||
.requires(MItemTags.TOOLS_HAMMERS)
|
||||
.requires(input)
|
||||
.unlockedBy(MItemTags.TOOLS_HAMMERS)
|
||||
.unlockedBy(input)
|
||||
.save(consumer)
|
||||
}
|
||||
|
||||
fun hammerRecipe(output: ItemLike, input: TagKey<Item>, consumer: RecipeOutput) {
|
||||
ShapelessRecipeBuilder(RecipeCategory.MISC, output, 1)
|
||||
.requires(MItemTags.TOOLS_HAMMERS)
|
||||
.requires(input)
|
||||
.unlockedBy(MItemTags.TOOLS_HAMMERS)
|
||||
.unlockedBy(input)
|
||||
.save(consumer)
|
||||
}
|
||||
|
||||
fun addShapelessRecipes(consumer: RecipeOutput) {
|
||||
for (color in DyeColor.entries) {
|
||||
@ -37,4 +57,8 @@ fun addShapelessRecipes(consumer: RecipeOutput) {
|
||||
.unlockedBy(Items.MINECART)
|
||||
.unlockedBy(MRegistry.CARGO_CRATES.item)
|
||||
.save(consumer)
|
||||
|
||||
hammerRecipe(MItems.TRITANIUM_PLATE, MItemTags.TRITANIUM_INGOTS, consumer)
|
||||
hammerRecipe(MItems.IRON_PLATE, Tags.Items.INGOTS_IRON, consumer)
|
||||
hammerRecipe(MItems.GOLD_PLATE, Tags.Items.INGOTS_GOLD, consumer)
|
||||
}
|
||||
|
@ -119,6 +119,9 @@ fun addTags(tagsProvider: TagsProvider) {
|
||||
tagsProvider.items.Appender(Tags.Items.SHEARS).add(MItems.TRITANIUM_SHEARS)
|
||||
tagsProvider.items.Appender(Tags.Items.TOOLS_SHIELDS).add(MItems.TRITANIUM_SHIELD)
|
||||
|
||||
tagsProvider.items.Appender(MItemTags.TOOLS_HAMMERS).add(MItems.EXPLOSIVE_HAMMER)
|
||||
tagsProvider.items.forge("tools").add(MItemTags.TOOLS_HAMMERS)
|
||||
|
||||
tagsProvider.items.Appender(MItemTags.UPGRADES).add(MItems.CreativeUpgrades.LIST)
|
||||
|
||||
tagsProvider.blocks.Appender(BlockTags.STAIRS)
|
||||
|
@ -29,6 +29,7 @@ import net.minecraft.world.level.Explosion
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.phys.AABB
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import net.minecraftforge.common.ForgeHooks
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.common.Tags
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent
|
||||
@ -73,6 +74,70 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
|
||||
put(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", -3.4, AttributeModifier.Operation.ADDITION))
|
||||
}
|
||||
|
||||
override fun hasCraftingRemainingItem(itemStack: ItemStack): Boolean = true
|
||||
|
||||
override fun getCraftingRemainingItem(itemStack: ItemStack): ItemStack {
|
||||
val player = ForgeHooks.getCraftingPlayer() ?: return itemStack.copy()
|
||||
if (player.level().isClientSide) return itemStack.copy()
|
||||
|
||||
if (!isPrimed(itemStack)) {
|
||||
itemStack.hurtAndBreak(1, player) {}
|
||||
} else {
|
||||
val level = player.level() as ServerLevel
|
||||
|
||||
itemStack.hurtAndBreak(level.random.nextInt(1, 20), player) {}
|
||||
unprime(itemStack)
|
||||
|
||||
val (ex, ey, ez) = Vector.atCenterOf(player.blockPosition())
|
||||
|
||||
val exp = Explosion(player.level(), player, ex, ey, ez, 1f, false, if (ToolsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS) Explosion.BlockInteraction.DESTROY_WITH_DECAY else Explosion.BlockInteraction.KEEP)
|
||||
exp.explode()
|
||||
exp.finalizeExplosion(true)
|
||||
|
||||
if (!ToolsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS)
|
||||
exp.clearToBlow()
|
||||
|
||||
MatteryBlockEntity.watchingPlayers(player.position(), level)
|
||||
.filter { it.position.distanceTo(player.position()) <= 64.0 }
|
||||
.forEach {
|
||||
it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it]))
|
||||
}
|
||||
|
||||
if (!player.isCreative) {
|
||||
val copy = itemStack.copy()
|
||||
|
||||
if (!itemStack.isEmpty && player.random.nextDouble() <= ToolsConfig.ExplosiveHammer.FLY_OFF_CHANCE) {
|
||||
val (x, y, z) = player.position
|
||||
val entity = ItemEntity(level, x, y, z, copy)
|
||||
|
||||
val (xv, yv, zv) = player.getViewVector(0f)
|
||||
|
||||
entity.deltaMovement = Vec3(
|
||||
player.random.nextDouble() * xv * -0.5,
|
||||
player.random.nextDouble() * yv * -0.5,
|
||||
(player.random.nextDouble() + 0.65) * zv * -2.0,
|
||||
)
|
||||
|
||||
level.addFreshEntity(entity)
|
||||
|
||||
if (player.random.nextDouble() <= ToolsConfig.ExplosiveHammer.FLY_OFF_DAMAGE_CHANCE) {
|
||||
player.invulnerableTime = 0
|
||||
val dmg = ToolsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE + player.random.nextDouble() * (ToolsConfig.ExplosiveHammer.FLY_OFF_MAX_DAMAGE - ToolsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE)
|
||||
player.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat())
|
||||
}
|
||||
|
||||
itemStack.shrink(itemStack.count)
|
||||
} else if (player.random.nextDouble() <= ToolsConfig.ExplosiveHammer.SELF_HARM_CHANCE) {
|
||||
player.invulnerableTime = 0
|
||||
val dmg = ToolsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE + player.random.nextDouble() * (ToolsConfig.ExplosiveHammer.SELF_HARM_MAX_DAMAGE - ToolsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE)
|
||||
player.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack.copy()
|
||||
}
|
||||
|
||||
override fun getAttributeModifiers(
|
||||
slot: EquipmentSlot,
|
||||
itemStack: ItemStack
|
||||
@ -264,8 +329,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
|
||||
val item = event.itemStack.item
|
||||
|
||||
if (item is ExplosiveHammerItem) {
|
||||
val (x, y, z) = event.pos
|
||||
item.attackAt(event.itemStack, event.entity, Vec3(x + 0.5, y + 0.5, z + 0.5), event.face?.opposite?.normal?.toDoubleVector() ?: event.entity.getViewVector(0f), event.hand)
|
||||
item.attackAt(event.itemStack, event.entity, Vector.atCenterOf(event.pos), event.face?.opposite?.normal?.toDoubleVector() ?: event.entity.getViewVector(0f), event.hand)
|
||||
event.isCanceled = true
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ object MItemTags {
|
||||
|
||||
val PISTONS: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "pistons"))
|
||||
|
||||
val TOOLS_HAMMERS: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "tools/hammers"))
|
||||
|
||||
val HARDENED_GLASS_PANES: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "hardened_glass_panes"))
|
||||
val HARDENED_GLASS_PANES_BLACK: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "hardened_glass_panes/black"))
|
||||
val HARDENED_GLASS_PANES_BLUE: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "hardened_glass_panes/blue"))
|
||||
|
Loading…
Reference in New Issue
Block a user