Better belt breaking

This commit is contained in:
JozsefA 2021-05-11 11:39:13 -07:00
parent f6937ffb0c
commit 916b187aa8
4 changed files with 62 additions and 11 deletions

View file

@ -126,7 +126,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
/*
* FIXME
*
*
* @Override
* public Material getMaterial(BlockState state) {
* return state.get(CASING) ? Material.WOOD : Material.WOOL;
@ -474,6 +474,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
BlockPos currentPos = nextSegmentPosition(state, pos, forward);
if (currentPos == null)
continue;
world.sendBlockBreakProgress(currentPos.hashCode(), currentPos, -1);
BlockState currentState = world.getBlockState(currentPos);
if (!AllBlocks.BELT.has(currentState))
continue;

View file

@ -0,0 +1,22 @@
package com.simibubi.create.foundation;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.relays.belt.BeltBlock;
import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
public class BreakProgressHook {
public static void whenBreaking(ClientWorld world, WorldRenderer renderer, int playerEntityId, BlockPos pos, int progress) {
if (AllBlocks.BELT.has(world.getBlockState(pos))) {
BeltTileEntity belt = (BeltTileEntity) world.getTileEntity(pos);
for (BlockPos beltPos : BeltBlock.getBeltChain(world, belt.getController())) {
renderer.sendBlockBreakProgress(beltPos.hashCode(), beltPos, progress);
}
}
}
}

View file

@ -0,0 +1,27 @@
package com.simibubi.create.foundation.mixin;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.simibubi.create.foundation.BreakProgressHook;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
@Mixin(ClientWorld.class)
public class BreakProgressMixin {
@Shadow
@Final
private WorldRenderer worldRenderer;
private final ClientWorld self = (ClientWorld) (Object) this;
@Inject(at = @At("HEAD"), method = "sendBlockBreakProgress")
private void onBreakProgress(int playerEntityId, BlockPos pos, int progress, CallbackInfo ci) {
BreakProgressHook.whenBreaking(self, this.worldRenderer, playerEntityId, pos, progress);
}
}

View file

@ -5,16 +5,17 @@
"compatibilityLevel": "JAVA_8",
"refmap": "create.refmap.json",
"client": [
"TileWorldHookMixin",
"CancelTileEntityRenderMixin",
"FogColorTrackerMixin",
"LightUpdateMixin",
"NetworkLightUpdateMixin",
"RenderHooksMixin",
"ShaderCloseMixin",
"TileRemoveMixin",
"EntityContraptionInteractionMixin",
"StoreProjectionMatrixMixin"
"BreakProgressMixin",
"CancelTileEntityRenderMixin",
"EntityContraptionInteractionMixin",
"FogColorTrackerMixin",
"LightUpdateMixin",
"NetworkLightUpdateMixin",
"RenderHooksMixin",
"ShaderCloseMixin",
"StoreProjectionMatrixMixin",
"TileRemoveMixin",
"TileWorldHookMixin"
],
"injectors": {
"defaultRequire": 1