mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-20 14:16:26 -04:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95d56b58c1 | ||
|
|
1a3a9370f9 |
+31
@@ -0,0 +1,31 @@
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.cobblemon.mod.common.block.BlockExtensions;
|
||||
import com.cobblemon.mod.common.block.habitat.HabitatBlock;
|
||||
import com.cobblemon.mod.common.block.habitat.HabitatBlockEntity;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ExplosionDamageCalculator;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(ExplosionDamageCalculator.class)
|
||||
public class ExplosionDamageCalculatorMixin {
|
||||
@ModifyArg(
|
||||
method = "getBlockExplosionResistance",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Ljava/lang/Math;max(FF)F"),
|
||||
index = 0
|
||||
)
|
||||
public float customBlockResistance(float resistance, @Local(argsOnly = true) BlockState state, @Local(argsOnly = true) BlockGetter reader, @Local(argsOnly = true) BlockPos pos) {
|
||||
if (state.getBlock() instanceof BlockExtensions) {
|
||||
return ((BlockExtensions) state.getBlock()).getExplosionResistance(state, reader, pos);
|
||||
}
|
||||
return resistance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.cobblemon.mod.common.block.habitat.HabitatBlock;
|
||||
import com.cobblemon.mod.common.block.habitat.HabitatBlockEntity;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
@Mixin(ServerPlayerGameMode.class)
|
||||
public class ServerPlayerGameModeMixin {
|
||||
@Shadow @Final protected ServerPlayer player;
|
||||
|
||||
@ModifyVariable(
|
||||
method = "destroyBlock",
|
||||
at = @At(
|
||||
value = "STORE"
|
||||
),
|
||||
name = "bl2")
|
||||
private boolean habitatCorrectTool(boolean bl2, @Local(name = "blockState2") BlockState blockState2, @Local(name = "pos") BlockPos pos, @Local(name = "blockEntity") BlockEntity blockEntity) {
|
||||
if (blockState2.getBlock() instanceof HabitatBlock && blockEntity instanceof HabitatBlockEntity) {
|
||||
BlockState mimicState = ((HabitatBlockEntity) blockEntity).getMimickedState();
|
||||
return player.hasCorrectToolForDrops(mimicState);
|
||||
}
|
||||
return bl2;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.client;
|
||||
|
||||
import com.cobblemon.mod.common.block.BlockExtensions;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
@Mixin(MultiPlayerGameMode.class)
|
||||
public class MultiPlayerGameModeMixin {
|
||||
@Shadow @Final private Minecraft minecraft;
|
||||
|
||||
@ModifyVariable(
|
||||
method = "continueDestroyBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Direction;)Z",
|
||||
at = @At(value = "STORE"),
|
||||
name = "soundType"
|
||||
)
|
||||
private SoundType customSoundType(SoundType soundType, @Local(name = "posBlock") BlockPos posBlock, @Local(name = "blockState") BlockState blockState) {
|
||||
if (blockState.getBlock() instanceof BlockExtensions) {
|
||||
return ((BlockExtensions)blockState.getBlock()).getSoundType(blockState, minecraft.player.level(), posBlock);
|
||||
}
|
||||
return soundType;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -32,6 +33,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@@ -151,4 +153,13 @@ public abstract class EntityMixin {
|
||||
|
||||
original.call(pusher, d * pusheeReceivedForce.get(), 0.0, e * pusheeReceivedForce.get());
|
||||
}
|
||||
|
||||
@ModifyVariable(
|
||||
method = "play",
|
||||
at = @At(value = "STORE"),
|
||||
name = "soundType"
|
||||
)
|
||||
public SoundType customCombinedStepSounds(SoundType soundType, @Local(argsOnly = true) ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.block
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.level.BlockGetter
|
||||
import net.minecraft.world.level.block.SoundType
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
|
||||
interface BlockExtensions { // Exist only to have better Sound Calls
|
||||
fun getSoundType(state: BlockState, level: BlockGetter, pos: BlockPos): SoundType
|
||||
fun getExplosionResistance(state: BlockState, level: BlockGetter, pos: BlockPos): Float
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
package com.cobblemon.mod.common.block.habitat
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonBlockEntities
|
||||
import com.cobblemon.mod.common.block.BlockExtensions
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.world.InteractionResult
|
||||
@@ -25,7 +26,6 @@ import net.minecraft.world.level.block.SoundType
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
import net.minecraft.world.level.block.entity.CommandBlockEntity
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.minecraft.world.level.block.state.StateDefinition
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty
|
||||
@@ -36,10 +36,7 @@ import net.minecraft.world.phys.shapes.CollisionContext
|
||||
import net.minecraft.world.phys.shapes.Shapes
|
||||
import net.minecraft.world.phys.shapes.VoxelShape
|
||||
|
||||
class HabitatBlock(properties: Properties) : Block(properties), EntityBlock {
|
||||
var level: Level? = null
|
||||
var pos: BlockPos? = null
|
||||
|
||||
class HabitatBlock(properties: Properties) : Block(properties), EntityBlock, BlockExtensions {
|
||||
companion object {
|
||||
val CANCELS_REGULAR_SPAWNS = BooleanProperty.create("cancels_regular_spawns")
|
||||
val ACTIVATED_STYLE = BooleanProperty.create("activated_style")
|
||||
@@ -53,6 +50,10 @@ class HabitatBlock(properties: Properties) : Block(properties), EntityBlock {
|
||||
)
|
||||
}
|
||||
|
||||
private fun getBlockEntity(level: BlockGetter, pos: BlockPos): HabitatBlockEntity? {
|
||||
return level.getBlockEntity(pos) as? HabitatBlockEntity
|
||||
}
|
||||
|
||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||
super.createBlockStateDefinition(builder)
|
||||
builder.add(FACING, CANCELS_REGULAR_SPAWNS, ACTIVATED_STYLE)
|
||||
@@ -96,8 +97,8 @@ class HabitatBlock(properties: Properties) : Block(properties), EntityBlock {
|
||||
|
||||
if (player?.isCreative == true) return mutableListOf()
|
||||
|
||||
val mimic = blockEntity?.mimickedState?.block ?: return mutableListOf()
|
||||
return mutableListOf(ItemStack(mimic))
|
||||
val mimic = blockEntity?.mimickedState ?: return mutableListOf()
|
||||
return mimic.getDrops(params)
|
||||
}
|
||||
|
||||
override fun getRenderShape(state: BlockState): RenderShape {
|
||||
@@ -144,17 +145,20 @@ class HabitatBlock(properties: Properties) : Block(properties), EntityBlock {
|
||||
mimicState.block.spawnDestroyParticles(level, player, pos, mimicState)
|
||||
}
|
||||
|
||||
override fun onPlace(state: BlockState, level: Level, pos: BlockPos, oldState: BlockState, isMoving: Boolean) {
|
||||
super.onPlace(state, level, pos, oldState, isMoving)
|
||||
val blockEntity = level.getBlockEntity(pos) as? HabitatBlockEntity
|
||||
blockEntity?.updateLevelAndPos(level, pos)
|
||||
override fun getSoundType(state: BlockState, level: BlockGetter, pos: BlockPos): SoundType {
|
||||
return getBlockEntity(level, pos)?.mimickedState?.soundType ?: getSoundType(state)
|
||||
}
|
||||
|
||||
override fun getSoundType(state: BlockState): SoundType {
|
||||
val level = this.level ?: return super.getSoundType(state)
|
||||
val pos = this.pos ?: return super.getSoundType(state)
|
||||
val blockEntity = level.getBlockEntity(pos) as? HabitatBlockEntity
|
||||
val mimicState = blockEntity?.mimickedState ?: return super.getSoundType(state)
|
||||
return mimicState.soundType
|
||||
return super.getSoundType(state)
|
||||
}
|
||||
|
||||
override fun getDestroyProgress(state: BlockState, player: Player, level: BlockGetter, pos: BlockPos): Float {
|
||||
val mimicState = getBlockEntity(level, pos)?.mimickedState ?: return super.getDestroyProgress(state, player, level, pos)
|
||||
return super.getDestroyProgress(mimicState, player, level, pos) * 0.5F // Habitat Mimic Block breaks twice as long
|
||||
}
|
||||
|
||||
override fun getExplosionResistance(state: BlockState, level: BlockGetter, pos: BlockPos): Float {
|
||||
return getBlockEntity(level, pos)?.mimickedState?.block?.explosionResistance ?: getExplosionResistance()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,14 +250,6 @@ class HabitatBlockEntity(pos: BlockPos, state: BlockState) :
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLevelAndPos(level: Level, pos: BlockPos) {
|
||||
val block = this.blockState.block
|
||||
if (block is HabitatBlock) {
|
||||
block.level = level
|
||||
block.pos = pos
|
||||
}
|
||||
}
|
||||
|
||||
override fun affectSpawnable(detail: SpawnDetail, spawnablePosition: SpawnablePosition): Boolean {
|
||||
val spawningStyle = spawningStyle
|
||||
return if (spawningStyle is NaturalHabitatSpawning) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"client.ModelLoaderMixin",
|
||||
"client.ModelPartMixin",
|
||||
"client.MouseHandlerMixin",
|
||||
"client.MultiPlayerGameModeMixin",
|
||||
"client.OptionsMixin",
|
||||
"client.PlayerRendererMixin",
|
||||
"client.RecipeBookComponentMixin",
|
||||
@@ -58,6 +59,7 @@
|
||||
"EntitySkeletonMixin",
|
||||
"EntityStorageMixin",
|
||||
"EntityVillagerMixin",
|
||||
"ExplosionDamageCalculatorMixin",
|
||||
"ItemStackComponentizationFixMixin",
|
||||
"LecternBlockMixin",
|
||||
"LightningBoltMixin",
|
||||
@@ -75,6 +77,7 @@
|
||||
"PowderSnowBlockMixin",
|
||||
"ServerEntityMixin",
|
||||
"ServerLevelMixin",
|
||||
"ServerPlayerGameModeMixin",
|
||||
"ServerPlayerMixin",
|
||||
"ShearsDispenserBehaviorMixin",
|
||||
"SimpleBlockFeatureMixin",
|
||||
|
||||
Reference in New Issue
Block a user