forked from Hurricaaane/Presence-Footsteps
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Create Mod integration ( For when they can eventually fix their…
… end: Fabricators-of-Create/Create#1169 )
- Loading branch information
Showing
7 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/eu/ha3/presencefootsteps/compat/ContraptionCollidable.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,8 @@ | ||
package eu.ha3.presencefootsteps.compat; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public interface ContraptionCollidable { | ||
BlockState getCollidedStateAt(BlockPos pos); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/eu/ha3/presencefootsteps/compat/PFMixinPlugin.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,46 @@ | ||
package eu.ha3.presencefootsteps.compat; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
public class PFMixinPlugin implements IMixinConfigPlugin { | ||
private static final String MIXIN_PACKAGE = "eu.ha3.presencefootsteps.mixins.compat"; | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) { } | ||
|
||
@Override | ||
public String getRefMapperConfig() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
if (mixinClassName.startsWith(MIXIN_PACKAGE)) { | ||
if (mixinClassName.indexOf("create") != -1) { | ||
return FabricLoader.getInstance().isModLoaded("create"); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { } | ||
|
||
@Override | ||
public List<String> getMixins() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/eu/ha3/presencefootsteps/mixins/compat/create/MEntity.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,38 @@ | ||
package eu.ha3.presencefootsteps.mixins.compat.create; | ||
|
||
import org.apache.logging.log4j.util.TriConsumer; | ||
import org.spongepowered.asm.mixin.Dynamic; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import eu.ha3.presencefootsteps.compat.ContraptionCollidable; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
@Mixin(value = Entity.class, priority = 9999 /* Run us last */) | ||
abstract class MEntity implements ContraptionCollidable { | ||
|
||
private int lastCollidedContraptionStateTick = -1; | ||
private BlockState lastCollidedContraptionState = Blocks.AIR.getDefaultState(); | ||
|
||
@Dynamic( | ||
value = "forCollission(center, consumer) - Private member injected by Create. See: https://github.com/Fabricators-of-Create/Create/blob/49cc17e3de33c965b1c409130abe436821f7410c/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java#L81C21-L81C21" | ||
) | ||
@Shadow | ||
private void forCollision(Vec3d anchorPos, TriConsumer<Object, BlockState, BlockPos> action) {} | ||
|
||
@Override | ||
public BlockState getCollidedStateAt(BlockPos pos) { | ||
if (lastCollidedContraptionStateTick != ((Entity)(Object)this).age) { | ||
lastCollidedContraptionStateTick = ((Entity)(Object)this).age; | ||
forCollision(((Entity)(Object)this).getPos().add(0, -0.2, 0), (unused, state, p) -> { | ||
if (pos.equals(p)) { | ||
lastCollidedContraptionState = state; | ||
} | ||
}); | ||
} | ||
return lastCollidedContraptionState; | ||
} | ||
} |
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
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