mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-04 03:17:55 +00:00
@@ -44,7 +44,6 @@ import java.util.EnumSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
|
|
||||||
import static dan200.computercraft.shared.ComputerCraftRegistry.init;
|
import static dan200.computercraft.shared.ComputerCraftRegistry.init;
|
||||||
|
|
||||||
public final class ComputerCraft implements ModInitializer
|
public final class ComputerCraft implements ModInitializer
|
||||||
|
@@ -18,6 +18,7 @@ import net.minecraft.client.render.Camera;
|
|||||||
import net.minecraft.client.render.VertexConsumer;
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
|
||||||
@@ -40,8 +41,12 @@ public final class CableHighlightRenderer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HitResult hitResult = MinecraftClient.getInstance().crosshairTarget;
|
||||||
|
|
||||||
|
Vec3d hitPos = hitResult != null ? hitResult.getPos() : new Vec3d( d, e, f );
|
||||||
|
|
||||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ),
|
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ),
|
||||||
new Vec3d( d, e, f ).subtract( pos.getX(),
|
hitPos.subtract( pos.getX(),
|
||||||
pos.getY(),
|
pos.getY(),
|
||||||
pos.getZ() ) ) ? CableShapes.getModemShape( state ) : CableShapes.getCableShape(
|
pos.getZ() ) ) ? CableShapes.getModemShape( state ) : CableShapes.getCableShape(
|
||||||
state );
|
state );
|
||||||
|
@@ -7,6 +7,7 @@ package dan200.computercraft.fabric.mixin;
|
|||||||
|
|
||||||
import dan200.computercraft.shared.common.TileGeneric;
|
import dan200.computercraft.shared.common.TileGeneric;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -26,12 +27,18 @@ import java.util.Collection;
|
|||||||
public class MixinWorld
|
public class MixinWorld
|
||||||
{
|
{
|
||||||
@Shadow
|
@Shadow
|
||||||
protected boolean iteratingTickingBlockEntities;
|
private boolean iteratingTickingBlockEntities;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public boolean isInBuildLimit( BlockPos pos )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Inject( method = "addBlockEntity", at = @At( "HEAD" ) )
|
@Inject( method = "addBlockEntity", at = @At( "HEAD" ) )
|
||||||
public void addBlockEntity( @Nullable BlockEntity entity, CallbackInfo info )
|
public void addBlockEntity( @Nullable BlockEntity entity, CallbackInfo info )
|
||||||
{
|
{
|
||||||
if( entity != null && !entity.isRemoved() && entity.getWorld() != null && entity.getWorld().isInBuildLimit( entity.getPos() ) && iteratingTickingBlockEntities )
|
if( entity != null && !entity.isRemoved() && this.isInBuildLimit( entity.getPos() ) && iteratingTickingBlockEntities )
|
||||||
{
|
{
|
||||||
setWorld( entity, this );
|
setWorld( entity, this );
|
||||||
}
|
}
|
||||||
@@ -41,7 +48,7 @@ public class MixinWorld
|
|||||||
{
|
{
|
||||||
if( entity.getWorld() != world && entity instanceof TileGeneric )
|
if( entity.getWorld() != world && entity instanceof TileGeneric )
|
||||||
{
|
{
|
||||||
entity.setWorld( (World) world ); //TODO why?
|
entity.setWorld( (World) world );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
||||||
@@ -232,9 +231,8 @@ public class BlockCable extends BlockGeneric implements Waterloggable
|
|||||||
public void onPlaced( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack )
|
public void onPlaced( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
if( tile instanceof TileCable )
|
if( tile instanceof TileCable cable )
|
||||||
{
|
{
|
||||||
TileCable cable = (TileCable) tile;
|
|
||||||
if( cable.hasCable() )
|
if( cable.hasCable() )
|
||||||
{
|
{
|
||||||
cable.connectionsChanged();
|
cable.connectionsChanged();
|
||||||
|
@@ -56,9 +56,8 @@ public abstract class ItemBlockCable extends BlockItem
|
|||||||
world.playSound( null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
|
world.playSound( null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
|
||||||
|
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
if( tile instanceof TileCable )
|
if( tile instanceof TileCable cable )
|
||||||
{
|
{
|
||||||
TileCable cable = (TileCable) tile;
|
|
||||||
cable.modemChanged();
|
cable.modemChanged();
|
||||||
cable.connectionsChanged();
|
cable.connectionsChanged();
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
private final IWiredNode node = cable.getNode();
|
private final IWiredNode node = cable.getNode();
|
||||||
private boolean peripheralAccessAllowed;
|
private boolean peripheralAccessAllowed;
|
||||||
private boolean destroyed = false;
|
private boolean destroyed = false;
|
||||||
private Direction modemDirection = Direction.NORTH;
|
|
||||||
private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), cable )
|
private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), cable )
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -60,7 +59,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
@Override
|
@Override
|
||||||
public Vec3d getPosition()
|
public Vec3d getPosition()
|
||||||
{
|
{
|
||||||
BlockPos pos = getPos().offset( modemDirection );
|
BlockPos pos = getPos().offset( getDirection() );
|
||||||
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +70,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
return TileCable.this;
|
return TileCable.this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private boolean hasModemDirection = false;
|
|
||||||
private boolean connectionsFormed = false;
|
private boolean connectionsFormed = false;
|
||||||
|
|
||||||
public TileCable( BlockEntityType<? extends TileCable> type, BlockPos pos, BlockState state )
|
public TileCable( BlockEntityType<? extends TileCable> type, BlockPos pos, BlockState state )
|
||||||
@@ -176,8 +174,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private Direction getDirection()
|
private Direction getDirection()
|
||||||
{
|
{
|
||||||
refreshDirection();
|
Direction direction = getMaybeDirection();
|
||||||
return modemDirection == null ? Direction.NORTH : modemDirection;
|
return direction == null ? Direction.NORTH : direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasModem()
|
public boolean hasModem()
|
||||||
@@ -312,8 +310,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDirection();
|
|
||||||
|
|
||||||
if( modem.getModemState()
|
if( modem.getModemState()
|
||||||
.pollChanged() )
|
.pollChanged() )
|
||||||
{
|
{
|
||||||
@@ -327,7 +323,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
connectionsChanged();
|
connectionsChanged();
|
||||||
if( peripheralAccessAllowed )
|
if( peripheralAccessAllowed )
|
||||||
{
|
{
|
||||||
peripheral.attach( world, pos, modemDirection );
|
peripheral.attach( world, pos, getDirection() );
|
||||||
updateConnectedPeripherals();
|
updateConnectedPeripherals();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,20 +356,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Direction getMaybeDirection()
|
private Direction getMaybeDirection()
|
||||||
{
|
{
|
||||||
refreshDirection();
|
return getCachedState().get( BlockCable.MODEM ).getFacing();
|
||||||
return modemDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshDirection()
|
|
||||||
{
|
|
||||||
if( hasModemDirection )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasModemDirection = true;
|
|
||||||
modemDirection = getCachedState().get( BlockCable.MODEM )
|
|
||||||
.getFacing();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -412,7 +395,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
|||||||
{
|
{
|
||||||
super.setCachedState( state );
|
super.setCachedState( state );
|
||||||
if( state != null ) return;
|
if( state != null ) return;
|
||||||
hasModemDirection = false;
|
|
||||||
if( !world.isClient )
|
if( !world.isClient )
|
||||||
{
|
{
|
||||||
world.getBlockTickScheduler()
|
world.getBlockTickScheduler()
|
||||||
|
@@ -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 );
|
||||||
|
Reference in New Issue
Block a user