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.
Stapler updates, move tick logic to public methods
- Loading branch information
Showing
6 changed files
with
132 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package blue.endless.scarves.api; | ||
|
||
import java.util.List; | ||
|
||
import blue.endless.scarves.client.ScarfAttachment; | ||
import blue.endless.scarves.client.ScarfNode; | ||
import blue.endless.scarves.client.ScarvesClient; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.nbt.NbtList; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public class ScarfLogic { | ||
|
||
/** | ||
* Updates the ScarfAttachment with new scarf data and applies gravity. Should be called each tick by an IScarfHaver. | ||
*/ | ||
public static void updateScarfAttachment(ScarfAttachment attachment, World world, Entity entity, Vec3d anchorPosition, NbtList data) { | ||
List<ScarfNode> nodes = attachment.nodes(); | ||
while(nodes.size()>data.size()) nodes.remove(nodes.size()-1); | ||
|
||
Vec3d lastPos = anchorPosition; | ||
for(int i=0; i<data.size(); i++) { | ||
FabricSquare square = FabricSquare.fromCompound(data.getCompound(i)); | ||
if (nodes.size()<=i) { | ||
ScarfNode node = new ScarfNode(lastPos, square); | ||
nodes.add(node); | ||
} else { | ||
nodes.get(i).setSquare(square); | ||
lastPos = nodes.get(i).getPosition(); | ||
} | ||
|
||
ScarfNode node = nodes.get(i); | ||
Vec3d prospectivePosition = node.getPosition().add(0, ScarvesClient.SCARF_GRAVITY, 0); | ||
BlockPos blockInThatPosition = new BlockPos(prospectivePosition); | ||
if (world!=null) { | ||
if (!world.isTopSolid(blockInThatPosition, entity)) { | ||
node.setPosition(prospectivePosition); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Only updates gravity on the scarf. Should be called each tick by an IScarfHaver if their scarf never changes color, length, or patterns based on item data. | ||
*/ | ||
public static void updateGravityOnly(ScarfAttachment attachment, World world, Entity entity) { | ||
List<ScarfNode> nodes = attachment.nodes(); | ||
|
||
for(int i=0; i<nodes.size(); i++) { | ||
ScarfNode node = nodes.get(i); | ||
Vec3d prospectivePosition = node.getPosition().add(0, ScarvesClient.SCARF_GRAVITY, 0); | ||
BlockPos blockInThatPosition = new BlockPos(prospectivePosition); | ||
if (world!=null) { | ||
if (!world.isTopSolid(blockInThatPosition, entity)) { | ||
node.setPosition(prospectivePosition); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/blue/endless/scarves/mixin/EntityEquipmentMixin.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,23 @@ | ||
package blue.endless.scarves.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import blue.endless.scarves.ScarvesItems; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
|
||
@Mixin(LivingEntity.class) | ||
public class EntityEquipmentMixin { | ||
|
||
|
||
@Inject(at = { @At("HEAD") }, method = "getPreferredEquipmentSlot", cancellable = true) | ||
private static EquipmentSlot getPreferredEquipmentSlot(ItemStack stack, CallbackInfoReturnable<EquipmentSlot> ci) { | ||
if (stack.isOf(ScarvesItems.SCARF_STAPLER)) ci.setReturnValue(EquipmentSlot.HEAD); | ||
|
||
return null; | ||
} | ||
} |
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