generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/alluysl/alluyslorigins/mixin/BoatEntityMixin.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,40 @@ | ||
package alluysl.alluyslorigins.mixin; | ||
|
||
import alluysl.alluyslorigins.power.ModifySlipperinessPower; | ||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.vehicle.BoatEntity; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(BoatEntity.class) | ||
public abstract class BoatEntityMixin extends Entity { | ||
|
||
public BoatEntityMixin(EntityType<?> type, World world){ | ||
super(type, world); | ||
} | ||
|
||
@Shadow @Nullable public abstract Entity getPrimaryPassenger(); | ||
|
||
@Redirect(method = "method_7548", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getSlipperiness()F")) | ||
private float modifySlipperiness(Block block){ | ||
float base = block.getSlipperiness(); | ||
|
||
Entity passenger = getPrimaryPassenger(); | ||
|
||
if (passenger instanceof LivingEntity) | ||
for (ModifySlipperinessPower power : OriginComponent.getPowers(passenger, ModifySlipperinessPower.class)) | ||
if (power.doesModify(getVelocityAffectingPos(), true)) | ||
base = MathHelper.lerp(power.getValue(), base, 1.0F); | ||
|
||
return base; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/alluysl/alluyslorigins/mixin/LivingEntityMixin.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,32 @@ | ||
package alluysl.alluyslorigins.mixin; | ||
|
||
import alluysl.alluyslorigins.power.ModifySlipperinessPower; | ||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(LivingEntity.class) | ||
public abstract class LivingEntityMixin extends Entity { | ||
|
||
public LivingEntityMixin(EntityType<?> type, World world){ | ||
super(type, world); | ||
} | ||
|
||
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getSlipperiness()F")) | ||
private float modifySlipperiness(Block block){ | ||
float base = block.getSlipperiness(); | ||
|
||
for (ModifySlipperinessPower power : OriginComponent.getPowers(this, ModifySlipperinessPower.class)) | ||
if (power.doesModify(getVelocityAffectingPos(), false)) | ||
base = MathHelper.lerp(power.getValue(), base, 1.0F); | ||
|
||
return base; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/alluysl/alluyslorigins/power/ModifySlipperinessPower.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,40 @@ | ||
package alluysl.alluyslorigins.power; | ||
|
||
import io.github.apace100.origins.power.Power; | ||
import io.github.apace100.origins.power.PowerType; | ||
import io.github.apace100.origins.power.factory.condition.ConditionFactory; | ||
import net.minecraft.block.pattern.CachedBlockPosition; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class ModifySlipperinessPower extends Power { | ||
|
||
private final float value; | ||
private final Predicate<CachedBlockPosition> blockCondition; | ||
private final boolean affectBoats; | ||
|
||
public ModifySlipperinessPower(PowerType<Power> type, PlayerEntity player, float value, ConditionFactory<CachedBlockPosition>.Instance blockCondition, boolean affectBoats){ | ||
super(type, player); | ||
this.value = value; | ||
this.blockCondition = blockCondition; | ||
this.affectBoats = affectBoats; | ||
} | ||
|
||
public float getValue(){ | ||
return value; | ||
} | ||
|
||
public boolean doesModify(BlockPos pos, boolean isBoat){ | ||
return doesModify(new CachedBlockPosition(player.world, pos, true), isBoat); | ||
} | ||
|
||
public boolean doesModify(CachedBlockPosition pos, boolean isBoat){ | ||
if (isBoat && !affectBoats) | ||
return false; | ||
if (blockCondition == null) | ||
return true; | ||
return blockCondition.test(pos); | ||
} | ||
} |
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
4737664
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.
(The builds are unsuccessful due to TerraformersMC's Maven being down)