-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mechanical arm optimizations #8613
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
Open
KptKosmit91
wants to merge
3
commits into
Creators-of-Create:mc1.20.1/dev
Choose a base branch
from
KptKosmit91:mechanical-arm-optimizations
base: mc1.20.1/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,10 +54,16 @@ | |||||
|
||||||
public class ArmBlockEntity extends KineticBlockEntity implements TransformableBlockEntity { | ||||||
|
||||||
// Server Statics | ||||||
private static final int SearchInputsRate = 20; // the rate at which the arm will search for targets while in SEARCH_INPUTS phase | ||||||
private static int LastRandomSearchTickOffset = 0; | ||||||
|
||||||
// Server | ||||||
List<ArmInteractionPoint> inputs; | ||||||
List<ArmInteractionPoint> outputs; | ||||||
ListTag interactionPointTag; | ||||||
int randomSearchTickOffset; | ||||||
int forceSearchInputsTicks = 1; // ticks for how long the arm will search on every tick instead of every SearchInputsRate ticks (while in SEARCH_INPUTS phase) | ||||||
|
||||||
// Both | ||||||
float chasedPointProgress; | ||||||
|
@@ -142,12 +148,24 @@ public void tick() { | |||||
if (level.isClientSide) | ||||||
return; | ||||||
|
||||||
if (phase == Phase.MOVE_TO_INPUT) | ||||||
collectItem(); | ||||||
else if (phase == Phase.MOVE_TO_OUTPUT) | ||||||
depositItem(); | ||||||
else if (phase == Phase.SEARCH_INPUTS || phase == Phase.DANCING) | ||||||
searchForItem(); | ||||||
switch (phase) { | ||||||
case MOVE_TO_INPUT: | ||||||
collectItem(); | ||||||
break; | ||||||
case MOVE_TO_OUTPUT: | ||||||
depositItem(); | ||||||
break; | ||||||
case SEARCH_INPUTS: | ||||||
case DANCING: | ||||||
boolean forcedSearch = forceSearchInputsTicks > 0; | ||||||
if (forcedSearch || (level.getGameTime() + randomSearchTickOffset) % SearchInputsRate == 0) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably make it clear in the comments above that the offset will be modulo'd and explain why |
||||||
if(forcedSearch) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
forceSearchInputsTicks--; | ||||||
} | ||||||
searchForItem(); | ||||||
} | ||||||
break; | ||||||
} | ||||||
|
||||||
if (targetReached) | ||||||
lazyTick(); | ||||||
|
@@ -161,10 +179,16 @@ public void lazyTick() { | |||||
return; | ||||||
if (chasedPointProgress < .5f) | ||||||
return; | ||||||
if (phase == Phase.SEARCH_INPUTS || phase == Phase.DANCING) | ||||||
checkForMusic(); | ||||||
if (phase == Phase.SEARCH_OUTPUTS) | ||||||
searchForDestination(); | ||||||
|
||||||
switch (phase){ | ||||||
case SEARCH_INPUTS: | ||||||
case DANCING: | ||||||
checkForMusic(); | ||||||
break; | ||||||
case SEARCH_OUTPUTS: | ||||||
searchForDestination(); | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
private void checkForMusic() { | ||||||
|
@@ -240,10 +264,21 @@ public void destroy() { | |||||
private ArmInteractionPoint getTargetedInteractionPoint() { | ||||||
if (chasedPointIndex == -1) | ||||||
return null; | ||||||
if (phase == Phase.MOVE_TO_INPUT && chasedPointIndex < inputs.size()) | ||||||
return inputs.get(chasedPointIndex); | ||||||
if (phase == Phase.MOVE_TO_OUTPUT && chasedPointIndex < outputs.size()) | ||||||
return outputs.get(chasedPointIndex); | ||||||
|
||||||
switch (phase){ | ||||||
case MOVE_TO_INPUT: | ||||||
if(chasedPointIndex < inputs.size()) | ||||||
{ | ||||||
return inputs.get(chasedPointIndex); | ||||||
} | ||||||
break; | ||||||
case MOVE_TO_OUTPUT: | ||||||
if(chasedPointIndex < outputs.size()) | ||||||
{ | ||||||
return outputs.get(chasedPointIndex); | ||||||
} | ||||||
break; | ||||||
} | ||||||
return null; | ||||||
} | ||||||
|
||||||
|
@@ -267,7 +302,9 @@ protected void searchForItem() { | |||||
ArmInteractionPoint armInteractionPoint = inputs.get(i); | ||||||
if (!armInteractionPoint.isValid()) | ||||||
continue; | ||||||
for (int j = 0; j < armInteractionPoint.getSlotCount(); j++) { | ||||||
|
||||||
int slotCount = armInteractionPoint.getSlotCount(); | ||||||
for (int j = 0; j < slotCount; j++) { | ||||||
if (getDistributableAmount(armInteractionPoint, j) == 0) | ||||||
continue; | ||||||
|
||||||
|
@@ -365,6 +402,7 @@ protected void depositItem() { | |||||
ItemStack toInsert = heldItem.copy(); | ||||||
ItemStack remainder = armInteractionPoint.insert(toInsert, false); | ||||||
heldItem = remainder; | ||||||
forceSearchInputsTicks = 5; // might need it's own static variable. this should be atleast one tick if you want the arm to jump to another action quickly (for example when refilling blaze burners) | ||||||
|
||||||
if (armInteractionPoint instanceof JukeboxPoint && remainder.isEmpty()) | ||||||
award(AllAdvancements.MUSICAL_ARM); | ||||||
|
@@ -382,8 +420,10 @@ protected void depositItem() { | |||||
|
||||||
protected void collectItem() { | ||||||
ArmInteractionPoint armInteractionPoint = getTargetedInteractionPoint(); | ||||||
if (armInteractionPoint != null && armInteractionPoint.isValid()) | ||||||
for (int i = 0; i < armInteractionPoint.getSlotCount(); i++) { | ||||||
if (armInteractionPoint != null && armInteractionPoint.isValid()) { | ||||||
|
||||||
int slotCount = armInteractionPoint.getSlotCount(); | ||||||
for (int i = 0; i < slotCount; i++) { | ||||||
int amountExtracted = getDistributableAmount(armInteractionPoint, i); | ||||||
if (amountExtracted == 0) | ||||||
continue; | ||||||
|
@@ -401,6 +441,7 @@ protected void collectItem() { | |||||
.5f + Create.RANDOM.nextFloat() * .25f); | ||||||
return; | ||||||
} | ||||||
} | ||||||
|
||||||
phase = Phase.SEARCH_INPUTS; | ||||||
chasedPointProgress = 0; | ||||||
|
@@ -608,6 +649,12 @@ public void setLevel(Level level) { | |||||
for (ArmInteractionPoint output : outputs) { | ||||||
output.setLevel(level); | ||||||
} | ||||||
|
||||||
// ensures that not all mechanical arms search for targets on the same tick while in SEARCH_INPUTS phase | ||||||
// this only needs to be done on the server side | ||||||
if (!level.isClientSide) { | ||||||
randomSearchTickOffset = LastRandomSearchTickOffset++; | ||||||
} | ||||||
} | ||||||
|
||||||
private class SelectionModeValueBox extends CenteredSideValueBoxTransform { | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for the other static field