generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Double scarf gravity again, add trinket slot to stapler, add slot ico…
…ns, improve API
- Loading branch information
Showing
10 changed files
with
212 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package blue.endless.scarves; | ||
|
||
import java.util.ArrayList; | ||
|
||
import blue.endless.scarves.api.FabricSquare; | ||
import blue.endless.scarves.api.FabricSquareRegistry; | ||
import blue.endless.scarves.api.ScarvesApi; | ||
import blue.endless.scarves.api.WindVectorProvider; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.ItemConvertible; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public class ScarvesApiImpl implements ScarvesApi { | ||
private static ScarvesApiImpl INSTANCE = new ScarvesApiImpl(); | ||
|
||
private ArrayList<WindVectorProvider> windProviders = new ArrayList<>(); | ||
|
||
public static ScarvesApiImpl getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void register(Block block, String textureId) { | ||
FabricSquareRegistry.register(block, textureId); | ||
} | ||
|
||
@Override | ||
public void register(ItemConvertible item, FabricSquare square) { | ||
FabricSquareRegistry.register(item, square); | ||
} | ||
|
||
@Override | ||
public void provideWind(WindVectorProvider wind) { | ||
windProviders.add(wind); | ||
} | ||
|
||
@Override | ||
public Vec3d getWind(World world, Vec3d pos) { | ||
Vec3d result = new Vec3d(0,0,0); | ||
|
||
for(WindVectorProvider provider : windProviders) { | ||
result = result.add(provider.apply(world, pos)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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
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,55 @@ | ||
package blue.endless.scarves.api; | ||
|
||
import blue.endless.scarves.ScarvesApiImpl; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.ItemConvertible; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public interface ScarvesApi { | ||
|
||
public static ScarvesApi instance() { | ||
return ScarvesApiImpl.getInstance(); | ||
} | ||
|
||
//API | ||
|
||
/** | ||
* Registers a block and allows it to be used in the left or right slots of the Scarf Stapler. The center of the | ||
* texture will be used for the appearance of the square. | ||
* | ||
* <p>Notes: Animated textures, and textures that have been synthetically stitched into the texture atlas used for | ||
* blocks and items, will all work seamlessly. Glowing blocks will automatically be rendered emissively. | ||
* Substituting a different texture from the atlas, a vanilla texture, a texture from a namespace you do not own, | ||
* these things are ALL ALLOWED. Cut out the middle of the diamond pickaxe texture and put it on a square, I'm not | ||
* your dad. Basically, if you can figure out its name, it's fair game. Putting any invalid identifier, including | ||
* "", will result in the pink checkers we all know and love. | ||
* | ||
* @param block The block to be accepted as a Fabric Square by the Scarf Stapler in its left or right slot. | ||
* @param textureId The resulting fabric square's appearance. For example, if you use cube_all, the same identifier | ||
* string that you use for the "all" texture parameter in the block's model will work here. | ||
*/ | ||
void register(Block block, String textureId); | ||
|
||
/** | ||
* Registers a block, item, or other item-like object and allows it to be used in the left or right slots of the | ||
* Scarf Stapler. The appearance of the square will be governed completely by the FabricSquare provided. | ||
* | ||
* <p>See Also: {@link #register(Block, String)} | ||
* | ||
* @param item The item or item-like object to be accepted as a Fabric Square by the Scarf Stapler in its left or | ||
* right slot. | ||
* @param square The appearance this item should have when stitched to the end of a scarf. | ||
*/ | ||
public void register(ItemConvertible item, FabricSquare square); | ||
|
||
/** | ||
* Registers a wind provider. These providers let Scarves know about wind that may vary based on location in the | ||
* world. This allows scarves to move in unison with other wind-affected objects, or serve as indicators of strong | ||
* winds for mods which provide windmills. | ||
* @param wind A function which yields a Vec3d of wind direction/strength at the provided world location. | ||
*/ | ||
public void provideWind(WindVectorProvider wind); | ||
|
||
public Vec3d getWind(World world, Vec3d pos); | ||
} |
17 changes: 13 additions & 4 deletions
17
src/main/java/blue/endless/scarves/api/ScarvesIntegration.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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package blue.endless.scarves.api; | ||
|
||
/** | ||
* This interface can be registered as an entrypoint with the "scarves" id, in order to do mod interop things, such as | ||
* making your blocks/items work in the Scarf Stapler, or letting Scarves know which way the wind | ||
* is blowing. | ||
*/ | ||
public interface ScarvesIntegration { | ||
/** | ||
* The main thing you can do here is safely call {@link FabricSquareRegistry#register(net.minecraft.block.Block, net.minecraft.util.Identifier)} | ||
* | ||
* <p>Set this class aside and don't touch it, and when this method is called register your blocks as fabric squares! | ||
* Retained for ModFest compatibility. Please move to {@link #integrateWithScarves(ScarvesApi)} as soon as possible. | ||
*/ | ||
void integrateWithScarves(); | ||
@Deprecated(forRemoval = true) | ||
default void integrateWithScarves() {} | ||
|
||
/** | ||
* Allows you to call methods on ScarvesApi without worrying about a hard dependency! | ||
*/ | ||
default void integrateWithScarves(ScarvesApi api) {} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/blue/endless/scarves/api/WindVectorProvider.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,10 @@ | ||
package blue.endless.scarves.api; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
@FunctionalInterface | ||
public interface WindVectorProvider extends BiFunction<World, Vec3d, Vec3d> { | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.