Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computer program cleanup #647

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c7c3c5c
Divide up ComputerBlockEntity.programData into data for individual pr…
kirderf1 Apr 29, 2024
03c7ad9
Clean up ComputerBlockEntity.markBlockForUpdate()
kirderf1 Apr 29, 2024
918562a
Interact with sburb client data through new class SburbClientData
kirderf1 Apr 29, 2024
753417f
Reorganize serialization functions
kirderf1 Apr 29, 2024
fb03a76
New class SburbServerData
kirderf1 Apr 29, 2024
b8ca21d
Access ButtonListProgram buttons by index through a list instead of a…
kirderf1 May 5, 2024
a44065c
Rename ButtonListProgram.getStringList() and change return type to st…
kirderf1 May 5, 2024
531dbff
Add clear button in getInterfaceData()
kirderf1 May 6, 2024
34f96a8
Clean up button text iteration in ButtonListProgram.onUpdateGui()
kirderf1 May 6, 2024
3f7db0a
Provide button press handler alongside button message in getInterface…
kirderf1 May 6, 2024
6b334d5
Change button data message to use Component instead of UnlocalizedString
kirderf1 May 6, 2024
30d0b4b
Cleanup message drawing, and use Component instead of UnlocalizedString
kirderf1 May 6, 2024
a8c5c64
Incorporate ComputerBlockEntity.latestmessage into SburbClientData an…
kirderf1 Oct 1, 2024
591fcba
Move ComputerBlock.insertDisk() to ComputerBlockEntity
kirderf1 Dec 8, 2024
b583b48
Make ComputerBlockEntity.installedPrograms private
kirderf1 Dec 8, 2024
2feee63
Make ComputerBlockEntity.owner private
kirderf1 Dec 9, 2024
15367c9
Register gui computer program suppliers instead of classes
kirderf1 Dec 9, 2024
14d75f4
Replace int program id with enum program type
kirderf1 Jan 1, 2025
88b7591
Move disk and handler from ProgramData into ProgramType
kirderf1 Jan 1, 2025
7caa3b5
Rework ComputerBlockEntity.gui field into just a callback
kirderf1 Jan 1, 2025
32e5651
Turn ProgramType from enum to final class
kirderf1 Jan 1, 2025
a3883a9
Add sburb_ prefix to client/server program types
kirderf1 Jan 1, 2025
0c45eb2
Determine program icon based on program type name
kirderf1 Jan 1, 2025
a5e6ddd
Change update call direction between ButtonListProgram and extenders
kirderf1 Jan 1, 2025
063c0fb
Clean up ComputerProgram, renaming it to ProgramGui
kirderf1 Jan 1, 2025
0e40fe4
Move message storing and drawing out of ButtonListProgram
kirderf1 Jan 1, 2025
c51606c
Convert ButtonListProgram into a helper object
kirderf1 Jan 1, 2025
1f5681a
Add gui suffix to ProgramGui implementors
kirderf1 Jan 1, 2025
da8091d
Create client.gui.computer package
kirderf1 Jan 1, 2025
72e3fa9
Merge branch 'main' into computer-program-cleanup
kirderf1 Jan 5, 2025
e59d69d
Delegate DiskBurnerData
kirderf1 Jan 5, 2025
c1a10a6
Encapsulate ComputerBlockEntity.ownerId
kirderf1 Jan 5, 2025
06c5035
Generify ProgramGui and ProgramType with data type, and provide optio…
kirderf1 Jan 5, 2025
308bd5f
Optional access to sburb program data
kirderf1 Jan 5, 2025
0aa8c0a
Create helpers to bundle computer and program data
kirderf1 Jan 5, 2025
6e17488
Generalize program data write/read over interface
kirderf1 Jan 5, 2025
0a5467a
Create and store data for arbitrary program type in ComputerBlockEntity
kirderf1 Jan 5, 2025
790322e
Replace clearComputerData() with direct program data calls
kirderf1 Jan 5, 2025
36cd88e
Remove ComputerBlockEntity.programSelected
kirderf1 Jan 5, 2025
2f277a8
Add disk capacity constants
kirderf1 Jan 5, 2025
cf006c5
Store disk items inside computer
kirderf1 Jan 5, 2025
7732f5f
Unify CompoundTag variable name in ComputerBlockEntity
kirderf1 Jan 5, 2025
c308201
Create proper program type registry
kirderf1 Jan 5, 2025
973a3b8
Use program type as item component
kirderf1 Jan 5, 2025
7e1372e
Fix program icons still rendering on screen in bsod mode
kirderf1 Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,6 @@
"minestuck.predefine.title_already_set": "That player already has their title set to %s",
"minestuck.private_computer": "You are not allowed to access other players computers.",
"minestuck.program.client.client_active_message": "Client is already active",
"minestuck.program.client.connect_button": "%s",
"minestuck.program.client.resume_client_message": "Waiting for server...",
"minestuck.program.client.select_color_button": "Select a Color",
"minestuck.program.client.select_message": "Select a server below",
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/mraof/minestuck/Minestuck.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.mraof.minestuck.blockentity.MSBlockEntityTypes;
import com.mraof.minestuck.command.MSSuggestionProviders;
import com.mraof.minestuck.command.argument.MSArgumentTypes;
import com.mraof.minestuck.computer.ProgramData;
import com.mraof.minestuck.computer.editmode.DeployList;
import com.mraof.minestuck.effects.MSEffects;
import com.mraof.minestuck.entity.MSEntityTypes;
Expand Down Expand Up @@ -143,8 +142,6 @@ private void mainThreadSetup()

MSPottedSaplings.addSaplingsToPot();

ProgramData.init();

BlockCopier.addStep(new ComputerBlockProcess());
BlockCopier.addStep(new TransportalizerBlockProcess());
if(ModList.get().isLoaded("refinedstorage"))
Expand Down
61 changes: 7 additions & 54 deletions src/main/java/com/mraof/minestuck/block/machine/ComputerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mraof.minestuck.block.MSProperties;
import com.mraof.minestuck.blockentity.ComputerBlockEntity;
import com.mraof.minestuck.client.gui.MSScreenFactories;
import com.mraof.minestuck.computer.ProgramData;
import com.mraof.minestuck.computer.ProgramType;
import com.mraof.minestuck.computer.theme.MSComputerThemes;
import com.mraof.minestuck.item.MSItems;
import com.mraof.minestuck.player.IdentifierHandler;
Expand Down Expand Up @@ -37,7 +37,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Map;
import java.util.OptionalInt;
import java.util.Objects;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
Expand Down Expand Up @@ -86,7 +86,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
ItemStack heldItem = player.getItemInHand(hand);
if(state.getValue(STATE) == State.OFF)
{
if(ProgramData.getProgramID(heldItem).isEmpty())
if(ProgramType.getForDisk(heldItem).isEmpty())
return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION;

turnOn(state, level, pos, player);
Expand All @@ -95,7 +95,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
if(!(level.getBlockEntity(pos) instanceof ComputerBlockEntity blockEntity))
return ItemInteractionResult.FAIL;

if(insertDisk(blockEntity, state, level, pos, player, hand))
if(blockEntity.insertDisk(player.getItemInHand(hand)))
return ItemInteractionResult.SUCCESS;
//insertion of code handled in ReadableSburbCodeItem onItemUseFirst()

Expand Down Expand Up @@ -133,59 +133,12 @@ private void turnOn(BlockState state, Level level, BlockPos pos, Player player)

if(level.getBlockEntity(pos) instanceof ComputerBlockEntity computer)
{
computer.owner = IdentifierHandler.encode(player);
computer.initializeOwner(Objects.requireNonNull(IdentifierHandler.encode(player)));

computer.setTheme(defaultTheme);
}
}

private boolean insertDisk(ComputerBlockEntity blockEntity, BlockState state, Level level, BlockPos pos, Player player, InteractionHand handIn)
{
if(blockEntity.isBroken())
return false;

ItemStack stackInHand = player.getItemInHand(handIn);
OptionalInt optionalId = ProgramData.getProgramID(stackInHand);

if(stackInHand.is(MSItems.BLANK_DISK.get()))
{
if(blockEntity.blankDisksStored < 2) //only allow two blank disks to be burned at a time
{
stackInHand.shrink(1);
blockEntity.blankDisksStored++;
blockEntity.setChanged();
level.sendBlockUpdated(pos, state, state, 3);
return true;
}
} else if(stackInHand.is(Items.MUSIC_DISC_11))
{
if(!level.isClientSide && blockEntity.installedPrograms.size() < 3)
{
stackInHand.shrink(1);
blockEntity.closeAll();
level.setBlock(pos, state.setValue(STATE, State.BROKEN), Block.UPDATE_CLIENTS);
blockEntity.setChanged();
level.sendBlockUpdated(pos, state, state, 3);
}
return true;
} else if(optionalId.isPresent())
{
int id = optionalId.getAsInt();
if(!level.isClientSide && !blockEntity.hasProgram(id))
{
stackInHand.shrink(1);
blockEntity.installedPrograms.add(id);
level.setBlock(pos, state.setValue(STATE, State.GAME_LOADED), Block.UPDATE_CLIENTS);
blockEntity.setChanged();
level.sendBlockUpdated(pos, state, state, 3);
ProgramData.getHandler(id).ifPresent(handler -> handler.onDiskInserted(blockEntity));
}
return true;
}

return false;
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
Expand All @@ -212,8 +165,8 @@ private void dropItems(Level level, int x, int y, int z, BlockState state)
be.closeAll();

//program disks
for(int id : be.installedPrograms)
Containers.dropItemStack(level, x, y, z, ProgramData.getItem(id));
be.installedPrograms().forEach(programType -> programType.diskItem()
.ifPresent(disk -> Containers.dropItemStack(level, x, y, z, disk.getDefaultInstance())));

//blank disks
Containers.dropItemStack(level, x, y, z, new ItemStack(MSItems.BLANK_DISK.get(), be.blankDisksStored));
Expand Down
Loading
Loading