Destruction states will now reset when breaking/replacing the block

This commit is contained in:
Sollace 2021-01-27 20:07:16 +02:00
parent 24cd6a9a3b
commit 543fd7aee0
3 changed files with 31 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.network.MsgBlockDestruction;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -49,6 +50,12 @@ public class BlockDestructionManager {
return amount;
}
public void onBlockChanged(BlockPos pos, BlockState oldState, BlockState newstate) {
if (oldState.getBlock() != newstate.getBlock()) {
clearBlockDestruction(pos);
}
}
public void tick() {
synchronized (locker) {
destructions.long2ObjectEntrySet().removeIf(entry -> entry.getValue().tick());

View file

@ -0,0 +1,23 @@
package com.minelittlepony.unicopia.mixin;
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.CallbackInfo;
import com.minelittlepony.unicopia.BlockDestructionManager;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.World;
@Mixin(ServerWorld.class)
abstract class MixinServerWorld extends World implements StructureWorldAccess {
private MixinServerWorld() {super(null, null, null, null, false, false, 0);}
@Inject(method = "onBlockChanged", at = @At("HEAD"))
private void onOnBlockChanged(BlockPos pos, BlockState oldState, BlockState newState, CallbackInfo info) {
((BlockDestructionManager.Source)this).getDestructionManager().onBlockChanged(pos, oldState, newState);
}
}

View file

@ -16,6 +16,7 @@
"MixinPlayerEntity",
"MixinProjectileEntity",
"MixinServerPlayerEntity",
"MixinServerWorld",
"MixinSheepEntity",
"MixinShulkerEntity",
"MixinTargetPredicate",