1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-06 04:17:56 +00:00

fix: BlockCable removedByPlayer

This commit is contained in:
Nikita Savyolov
2021-10-18 21:47:43 +03:00
parent 7a667b9028
commit 6fd8331e94
2 changed files with 56 additions and 50 deletions

View File

@@ -10,25 +10,26 @@ import com.google.common.collect.ImmutableMap;
import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.Waterloggable; import net.minecraft.block.Waterloggable;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView; import net.minecraft.world.*;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -122,52 +123,50 @@ public class BlockCable extends BlockGeneric implements Waterloggable
return getWaterloggedFluidState( state ); return getWaterloggedFluidState( state );
} }
// @Override public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid )
// public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid ) {
// { if( state.get( CABLE ) && state.get( MODEM ).getFacing() != null )
// if( state.get( CABLE ) && state.get( MODEM ).getFacing() != null ) {
// { BlockHitResult hit = world.raycast( new RaycastContext(
// BlockHitResult hit = world.raycast( new RaycastContext( WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ),
// WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, player
// RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, player ) );
// ) ); if( hit.getType() == HitResult.Type.BLOCK )
// if( hit.getType() == HitResult.Type.BLOCK ) {
// { BlockEntity tile = world.getBlockEntity( pos );
// BlockEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileCable cable && tile.hasWorld() )
// if( tile instanceof TileCable && tile.hasWorld() ) {
// {
// TileCable cable = (TileCable) tile; ItemStack item;
// BlockState newState;
// ItemStack item;
// BlockState newState; if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
// {
// if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) newState = state.with( MODEM, CableModemVariant.None );
// { item = new ItemStack( ComputerCraftRegistry.ModItems.WIRED_MODEM );
// newState = state.with( MODEM, CableModemVariant.None ); }
// item = new ItemStack( ComputerCraftRegistry.ModItems.WIRED_MODEM.get() ); else
// } {
// else newState = state.with( CABLE, false );
// { item = new ItemStack( ComputerCraftRegistry.ModItems.CABLE );
// newState = state.with( CABLE, false ); }
// item = new ItemStack( ComputerCraftRegistry.ModItems.CABLE.get() );
// } world.setBlockState( pos, correctConnections( world, pos, newState ), 3 );
//
// world.setBlockState( pos, correctConnections( world, pos, newState ), 3 ); cable.modemChanged();
// cable.connectionsChanged();
// cable.modemChanged(); if( !world.isClient && !player.getAbilities().creativeMode )
// cable.connectionsChanged(); {
// if( !world.isClient && !player.abilities.creativeMode ) Block.dropStack( world, pos, item );
// { }
// Block.dropStack( world, pos, item );
// } return false;
// }
// return false; }
// } }
// }
// } return true;
// }
// return super.removedByPlayer( state, world, pos, player, willHarvest, fluid );
// }
// TODO Re-implement, likely will need mixin // TODO Re-implement, likely will need mixin
// @Override // @Override

View File

@@ -25,6 +25,7 @@ import dan200.computercraft.shared.media.items.RecordMedia;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheral; import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheral;
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods; import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork; import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.turtle.FurnaceRefuelHandler; import dan200.computercraft.shared.turtle.FurnaceRefuelHandler;
import dan200.computercraft.shared.turtle.SignInspectHandler; import dan200.computercraft.shared.turtle.SignInspectHandler;
@@ -34,6 +35,7 @@ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.CommandBlockBlockEntity; import net.minecraft.block.entity.CommandBlockBlockEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@@ -123,6 +125,11 @@ public final class ComputerCraftProxyCommon
} }
} ); } );
PlayerBlockBreakEvents.BEFORE.register( ( world, player, pos, state, blockEntity ) -> {
if ( state.getBlock() instanceof BlockCable blockCable ) return blockCable.removedByPlayer( state, world, pos, player, false, null );
return true;
} );
// Config // Config
ServerLifecycleEvents.SERVER_STARTING.register( Config::serverStarting ); ServerLifecycleEvents.SERVER_STARTING.register( Config::serverStarting );
ServerLifecycleEvents.SERVER_STOPPING.register( Config::serverStopping ); ServerLifecycleEvents.SERVER_STOPPING.register( Config::serverStopping );