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