Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added annotation to the API that allows certain items to bypass KeyConflictContext activity checks, fixed an ItemStack null check, replaced a class check with a method call, and clarified a description. * Added method to the API the returns C&B key bindings. * 1) Added optional argument to the KeyBindingContext annotation that allows classes that use it to be added to ModConflictContext's active class collection; 2) Added an IMC that searches the class hierarchies of all classes of all of the sender's registered items for instances of the annotation that have this argument; 3) Refactored the active class collection to a hashset to avoid duplication. * Optimized IMC annotation search. * Remove nested type enum from ModKeyBinding and replaced the switch on its type with a switch on all its values not in ClientSide.
- Loading branch information
1 parent
61df578
commit 718a8ff
Showing
11 changed files
with
447 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
81 changes: 81 additions & 0 deletions
81
src/main/java/mod/chiselsandbits/api/KeyBindingContext.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package mod.chiselsandbits.api; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* The key bindings for the following operations are only active when holding C&B items: | ||
* | ||
* - "chisel" - Setting the chisel mode | ||
* - "postivepattern" - Setting the positive pattern mode | ||
* - "tapemeasure" - Setting the tape measure mode | ||
* - "rotateable" - Rotating blocks | ||
* - "menuitem" - Opening the radial menu | ||
* | ||
* If you put this annotation on a class that extends Item, you can allow C&B to bypass | ||
* the normal activity checks when holding an item that is an instance of that class. If | ||
* you include and set true the optional applyToSubClasses argument in the annotation or | ||
* use an IMC, this will apply not only to any item that is of that class, but also to | ||
* any class that extends that class. | ||
* | ||
* | ||
* If use any annotation with applyToSubClasses set to true, you need to send the | ||
* following IMC (of any type - String type is used below) after you register your items | ||
* to find/register/initialize those classes: | ||
* | ||
* FMLInterModComms.sendMessage( "chiselsandbits", "initkeybindingannotations", "" ); | ||
* | ||
* Doing so will not only find and initialize classes of registered items, but also any | ||
* base classes that registered items may extend, but are never directly instantiated. | ||
* | ||
* | ||
* | ||
* ~Example 1~ | ||
* Putting the following annotation on an item class will allow the key bindings for | ||
* chisel modes to be active when holding an item of that class: | ||
* | ||
* @KeyBindingContext( chisel ) | ||
* | ||
* The following two IMCs would do the same for item(s) of that class or of any subclass: | ||
* | ||
* FMLInterModComms.sendMessage( "chiselsandbits", "chisel", [myItemName] ); | ||
* | ||
* | ||
* | ||
* ~Example 2~ | ||
* The following IMC and IMC/annotation set will both allow the key binding for chisel | ||
* modes to be active when holding an item of that class or of any subclass: | ||
* | ||
* @KeyBindingContext( value = { "chisel", "menuitem" }, applyToSubClasses = true ) | ||
* AND | ||
* FMLInterModComms.sendMessage( "chiselsandbits", "initkeybindingannotations", "" ); | ||
* | ||
* OR | ||
* | ||
* FMLInterModComms.sendMessage( "chiselsandbits", "chisel", [myItemName] ); | ||
* FMLInterModComms.sendMessage( "chiselsandbits", "menuitem", [myItemName] ); | ||
* | ||
* | ||
*/ | ||
@Retention( RetentionPolicy.RUNTIME ) | ||
public @interface KeyBindingContext | ||
{ | ||
/** | ||
* A list of contexts that will allow all key bindings that use them to be active | ||
* when holding an item of a class (or a subclass, if applyToSubClasses is true) | ||
* with this annotation. | ||
* | ||
* @return a list of key bindings contexts | ||
*/ | ||
String[] value (); | ||
|
||
/** | ||
* If true, the key binding context activity check will be bypassed not only for items | ||
* of a class with this annotation, but also to items of any class that extends it. | ||
* | ||
* This argument is optional. | ||
* | ||
* @return whether or not this annotation applies to subclasses | ||
*/ | ||
boolean applyToSubClasses() default false; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mod.chiselsandbits.api; | ||
|
||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
@SideOnly( Side.CLIENT ) | ||
public enum ModKeyBinding | ||
{ | ||
//Misc | ||
ROTATE_CCW, | ||
ROTATE_CW, | ||
UNDO, | ||
REDO, | ||
MODE_MENU, | ||
ADD_TO_CLIPBOARD, | ||
PICK_BIT, | ||
|
||
//Chisel Modes | ||
SINGLE, | ||
SNAP2, | ||
SNAP4, | ||
SNAP8, | ||
LINE, | ||
PLANE, | ||
CONNECTED_PLANE, | ||
CUBE_SMALL, | ||
CUBE_MEDIUM, | ||
CUBE_LARGE, | ||
SAME_MATERIAL, | ||
DRAWN_REGION, | ||
CONNECTED_MATERIAL, | ||
|
||
//Positive Pattern Modes | ||
REPLACE, | ||
ADDITIVE, | ||
PLACEMENT, | ||
IMPOSE, | ||
|
||
//Tape Measure Modes | ||
BIT, | ||
BLOCK, | ||
DISTANCE; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.