Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复树脂块具有粘性的问题 #418

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/block/ResinBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dev.dubhe.anvilcraft.block;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.HalfTransparentBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

public class ResinBlock extends HalfTransparentBlock {
public ResinBlock(BlockBehaviour.Properties properties) {
super(properties);
}
/**
* @param level 世界
* @param state 方块状态
* @param pos 位置
* @param entity 实体
* @param fallDistance 掉落距离
*/

public void fallOn(@NotNull Level level,
@NotNull BlockState state,
@NotNull BlockPos pos,
Entity entity,
float fallDistance
) {
if (entity.isSuppressingBounce()) {
super.fallOn(level, state, pos, entity, fallDistance);
} else {
entity.causeFallDamage(fallDistance, 0.0F, level.damageSources().fall());
}

}


/**
* @param level 世界
* @param entity 实体
*/

public void updateEntityAfterFallOn(@NotNull BlockGetter level, Entity entity) {
if (entity.isSuppressingBounce()) {
super.updateEntityAfterFallOn(level, entity);
} else {
this.bounceUp(entity);
}

}

private void bounceUp(Entity entity) {
Vec3 vec3 = entity.getDeltaMovement();
if (vec3.y < 0.0) {
double d = entity instanceof LivingEntity ? 1.0 : 0.8;
entity.setDeltaMovement(vec3.x, -vec3.y * d, vec3.z);
}

}

/**
* @param level 世界
* @param pos 位置
* @param state 方块状态
* @param entity 实体
*/

public void stepOn(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, Entity entity) {
double d = Math.abs(entity.getDeltaMovement().y);
if (d < 0.1 && !entity.isSteppingCarefully()) {
double e = 0.4 + d * 0.2;
entity.setDeltaMovement(entity.getDeltaMovement().multiply(e, 1.0, e));
}

super.stepOn(level, pos, state, entity);
}
}
4 changes: 2 additions & 2 deletions common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dev.dubhe.anvilcraft.block.LavaCauldronBlock;
import dev.dubhe.anvilcraft.block.MagnetBlock;
import dev.dubhe.anvilcraft.block.PiezoelectricCrystalBlock;
import dev.dubhe.anvilcraft.block.ResinBlock;
import dev.dubhe.anvilcraft.block.RoyalAnvilBlock;
import dev.dubhe.anvilcraft.block.RoyalGrindstone;
import dev.dubhe.anvilcraft.block.RoyalSmithingTableBlock;
Expand Down Expand Up @@ -46,7 +47,6 @@
import net.minecraft.world.level.block.HalfTransparentBlock;
import net.minecraft.world.level.block.LayeredCauldronBlock;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.SlimeBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand Down Expand Up @@ -411,7 +411,7 @@ public class ModBlocks {
.save(provider))
.register();
public static final BlockEntry<? extends Block> RESIN_BLOCK = REGISTRATE
.block("resin_block", SlimeBlock::new)
.block("resin_block", ResinBlock::new)
.initialProperties(() -> Blocks.SLIME_BLOCK)
.blockstate((ctx, provider) -> {
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dubhe.anvilcraft.mixin.fabric;

import dev.dubhe.anvilcraft.block.ResinBlock;
import net.minecraft.world.level.block.Block;

import net.minecraft.world.level.block.SlimeBlock;
Expand All @@ -18,7 +19,8 @@ abstract class PistonMovingBlockEntityMixin {
target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z"
)
)
private static boolean isElastic(BlockState instance, Block block) {
return instance.getBlock() instanceof SlimeBlock;
private static boolean isElastic(BlockState instance, Block b) {
Block block = instance.getBlock();
return block instanceof SlimeBlock || block instanceof ResinBlock;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.dubhe.anvilcraft.mixin.forge;

import dev.dubhe.anvilcraft.block.ResinBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlimeBlock;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -19,6 +21,7 @@ abstract class PistonMovingBlockEntityMixin {
)
)
private static boolean isElastic(@NotNull BlockState instance) {
return instance.getBlock() instanceof SlimeBlock;
Block block = instance.getBlock();
return block instanceof SlimeBlock || block instanceof ResinBlock;
}
}
Loading