mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-26 23:42:18 +00:00
fix: advanced turtle gui interactive and correct turtles tick calling
This commit is contained in:
parent
121ef6e976
commit
e30f2a86f0
@ -40,11 +40,6 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
backgroundHeight = TEX_HEIGHT;
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
System.out.println(mouseX + " " + mouseY + " " + button);
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WidgetTerminal createTerminal()
|
||||
|
@ -65,14 +65,16 @@ public class WidgetTerminal extends ClickableWidget {
|
||||
innerHeight = termHeight * FONT_HEIGHT;
|
||||
}
|
||||
|
||||
private boolean inTermRegion( double mouseX, double mouseY )
|
||||
{
|
||||
return active && visible && mouseX >= innerX && mouseY >= innerY && mouseX < innerX + innerWidth && mouseY < innerY + innerHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked( double mouseX, double mouseY, int button )
|
||||
{
|
||||
ClientComputer computer = this.computer;
|
||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !inTermRegion( mouseX, mouseY ) ) return false;
|
||||
if( !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
@ -95,11 +97,8 @@ public class WidgetTerminal extends ClickableWidget {
|
||||
@Override
|
||||
public boolean mouseReleased( double mouseX, double mouseY, int button )
|
||||
{
|
||||
ClientComputer computer = this.computer;
|
||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !inTermRegion( mouseX, mouseY ) ) return false;
|
||||
if( !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
@ -125,11 +124,8 @@ public class WidgetTerminal extends ClickableWidget {
|
||||
@Override
|
||||
public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
|
||||
{
|
||||
ClientComputer computer = this.computer;
|
||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !inTermRegion( mouseX, mouseY ) ) return false;
|
||||
if( !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
@ -153,11 +149,8 @@ public class WidgetTerminal extends ClickableWidget {
|
||||
@Override
|
||||
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
|
||||
{
|
||||
ClientComputer computer = this.computer;
|
||||
if( computer == null || !computer.isColour() || delta == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !inTermRegion( mouseX, mouseY ) ) return false;
|
||||
if( !computer.isColour() || delta == 0 ) return false;
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
|
@ -221,7 +221,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
|
||||
return world.isClient ? null : (world1, pos, state1, tile) -> {
|
||||
if (tile instanceof TileComputerBase computer) {
|
||||
TileComputerBase.tick(world1, pos, state1, computer);
|
||||
computer.serverTick();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -271,43 +271,40 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
}
|
||||
}
|
||||
|
||||
public static void tick( World world, BlockPos pos, BlockState state, TileComputerBase tileComputerBase )
|
||||
public void serverTick()
|
||||
{
|
||||
if( !world.isClient )
|
||||
ServerComputer computer = createServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
ServerComputer computer = tileComputerBase.createServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If the computer isn't on and should be, then turn it on
|
||||
if( tileComputerBase.startOn || (tileComputerBase.fresh && tileComputerBase.on) )
|
||||
{
|
||||
computer.turnOn();
|
||||
tileComputerBase.startOn = false;
|
||||
}
|
||||
// If the computer isn't on and should be, then turn it on
|
||||
if( startOn || (fresh && on) )
|
||||
{
|
||||
computer.turnOn();
|
||||
startOn = false;
|
||||
}
|
||||
|
||||
computer.keepAlive();
|
||||
computer.keepAlive();
|
||||
|
||||
tileComputerBase.fresh = false;
|
||||
tileComputerBase.computerID = computer.getID();
|
||||
tileComputerBase.label = computer.getLabel();
|
||||
tileComputerBase.on = computer.isOn();
|
||||
fresh = false;
|
||||
computerID = computer.getID();
|
||||
label = computer.getLabel();
|
||||
on = computer.isOn();
|
||||
|
||||
if( computer.hasOutputChanged() )
|
||||
{
|
||||
tileComputerBase.updateOutput();
|
||||
}
|
||||
if( computer.hasOutputChanged() )
|
||||
{
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
// Update the block state if needed. We don't fire a block update intentionally,
|
||||
// as this only really is needed on the client side.
|
||||
tileComputerBase.updateBlockState( computer.getState() );
|
||||
// Update the block state if needed. We don't fire a block update intentionally,
|
||||
// as this only really is needed on the client side.
|
||||
updateBlockState( computer.getState() );
|
||||
|
||||
if( computer.hasOutputChanged() )
|
||||
{
|
||||
tileComputerBase.updateOutput();
|
||||
}
|
||||
if( computer.hasOutputChanged() )
|
||||
{
|
||||
updateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,9 +196,9 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Waterl
|
||||
return new TileTurtle(getTypeByFamily(getFamily()), pos, state, getFamily());
|
||||
}
|
||||
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
|
||||
// return world.isClient ? BlockTurtle.checkType( type, getTypeByFamily(getFamily()), TileTurtle::tick ) : super.getTicker(world, state, type);
|
||||
// }
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
|
||||
return world.isClient ? BlockTurtle.checkType( type, getTypeByFamily(getFamily()), ( world1, pos, state1, computer ) -> computer.clientTick() ) : super.getTicker(world, state, type);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.fabric.mixin.MixinBlockEntity;
|
||||
import dan200.computercraft.shared.ComputerCraftRegistry;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
||||
@ -256,10 +257,6 @@ public class TileTurtle extends TileComputerBase
|
||||
return super.onActivate( player, hand, hit );
|
||||
}
|
||||
|
||||
// public void setBlockPos( BlockPos pos ) {
|
||||
// ((MixinBlockEntity) (Object) this).setBlockPos(pos); // FIXME this looks really bad.
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
@ -278,26 +275,32 @@ public class TileTurtle extends TileComputerBase
|
||||
}
|
||||
}
|
||||
|
||||
public static void tick( World world, BlockPos pos, BlockState state,
|
||||
TileTurtle tileTurtle )
|
||||
@Override
|
||||
public void serverTick( )
|
||||
{
|
||||
tileTurtle.brain.update();
|
||||
if( !world.isClient && tileTurtle.inventoryChanged )
|
||||
super.serverTick();
|
||||
brain.update();
|
||||
if( inventoryChanged )
|
||||
{
|
||||
ServerComputer computer = tileTurtle.getServerComputer();
|
||||
ServerComputer computer = getServerComputer();
|
||||
if( computer != null )
|
||||
{
|
||||
computer.queueEvent( "turtle_inventory" );
|
||||
}
|
||||
|
||||
tileTurtle.inventoryChanged = false;
|
||||
for( int n = 0; n < tileTurtle.size(); n++ )
|
||||
inventoryChanged = false;
|
||||
for( int n = 0; n < size(); n++ )
|
||||
{
|
||||
tileTurtle.previousInventory.set( n, tileTurtle.getStack( n ).copy() );
|
||||
previousInventory.set( n, getStack( n ).copy() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void clientTick()
|
||||
{
|
||||
brain.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateBlockState( ComputerState newState )
|
||||
{}
|
||||
@ -564,7 +567,6 @@ public class TileTurtle extends TileComputerBase
|
||||
public ScreenHandler createMenu( int id, @Nonnull PlayerInventory inventory,
|
||||
@Nonnull PlayerEntity player )
|
||||
{
|
||||
System.out.println(inventory.player.getDisplayName());
|
||||
return new ContainerTurtle( id, inventory, brain );
|
||||
}
|
||||
|
||||
|
@ -252,11 +252,10 @@ public class TurtleBrain implements ITurtleAccess
|
||||
if( block == oldBlock.getBlock() )
|
||||
{
|
||||
BlockEntity newTile = world.getBlockEntity( pos );
|
||||
if( newTile instanceof TileTurtle )
|
||||
if( newTile instanceof TileTurtle newTurtle )
|
||||
{
|
||||
// Copy the old turtle state into the new turtle
|
||||
TileTurtle newTurtle = (TileTurtle) newTile;
|
||||
// newTurtle.setLocation( world, pos ); //FIXME: setLocation no longer exists.
|
||||
newTurtle.setWorld( world );
|
||||
newTurtle.transferStateFrom( oldOwner );
|
||||
newTurtle.createServerComputer()
|
||||
.setWorld( world );
|
||||
@ -459,6 +458,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
throw new UnsupportedOperationException( "Cannot run commands on the client" );
|
||||
}
|
||||
if( commandQueue.size() > 16 ) return MethodResult.of( false, "Too many ongoing turtle commands" );
|
||||
|
||||
// Issue command
|
||||
int commandID = issueCommand( command );
|
||||
@ -995,15 +995,12 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public MethodResult resume( Object[] response )
|
||||
{
|
||||
if( response.length < 3 || !(response[1] instanceof Number) || !(response[2] instanceof Boolean) )
|
||||
if( response.length < 3 || !(response[1] instanceof Number id) || !(response[2] instanceof Boolean) )
|
||||
{
|
||||
return pull;
|
||||
}
|
||||
|
||||
if( ((Number) response[1]).intValue() != command )
|
||||
{
|
||||
return pull;
|
||||
}
|
||||
if( id.intValue() != command ) return pull;
|
||||
|
||||
return MethodResult.of( Arrays.copyOfRange( response, 2, response.length ) );
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
super( ComputerCraftRegistry.ModContainers.TURTLE, id, canUse, computer, family );
|
||||
this.properties = properties;
|
||||
|
||||
System.out.println("Contaienr Turtle init" + properties);
|
||||
|
||||
addProperties( properties );
|
||||
|
||||
// Turtle inventory
|
||||
@ -113,7 +111,6 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
@Override
|
||||
public ItemStack transferSlot( @Nonnull PlayerEntity player, int slotNum )
|
||||
{
|
||||
System.out.println("transferSlot");
|
||||
if( slotNum >= 0 && slotNum < 16 )
|
||||
{
|
||||
return tryItemMerge( player, slotNum, 16, 52, true );
|
||||
@ -128,7 +125,6 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
@Nonnull
|
||||
private ItemStack tryItemMerge( PlayerEntity player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
|
||||
{
|
||||
System.out.println("tryItemMerge");
|
||||
Slot slot = slots.get( slotNum );
|
||||
ItemStack originalStack = ItemStack.EMPTY;
|
||||
if( slot != null && slot.hasStack() )
|
||||
@ -160,10 +156,4 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
}
|
||||
return originalStack;
|
||||
}
|
||||
@Override
|
||||
public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) {
|
||||
super.onSlotClick(slotIndex, button, actionType, player);
|
||||
|
||||
System.out.println("on slot click: " + slotIndex);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user