generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Lochnessdragon
committed
Mar 16, 2021
1 parent
07e85f9
commit 223dab6
Showing
36 changed files
with
720 additions
and
138 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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/github/originsplus/entity/IGrappleHook.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 com.github.originsplus.entity; | ||
|
||
public interface IGrappleHook { | ||
|
||
public boolean isGrapple(); | ||
public void setGrapple(boolean grapple); | ||
|
||
} |
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/com/github/originsplus/mixin/FishingBobberEntityMixin.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 com.github.originsplus.mixin; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
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.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import com.github.originsplus.entity.IGrappleHook; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.FishingBobberEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
@Mixin(FishingBobberEntity.class) | ||
public abstract class FishingBobberEntityMixin implements IGrappleHook { | ||
|
||
boolean grappler = false; | ||
|
||
FishingBobberEntity previousFishHook; | ||
|
||
@Override | ||
public boolean isGrapple() { | ||
// TODO Auto-generated method stub | ||
return grappler; | ||
} | ||
|
||
@Override | ||
public void setGrapple(boolean grapple) { | ||
this.grappler = grapple; | ||
} | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "removeIfInvalid", cancellable = true) | ||
public void checkGrappleInvalid(final PlayerEntity player, CallbackInfoReturnable<Boolean> info) { | ||
FishingBobberEntity entity = (FishingBobberEntity) (Object) this; | ||
|
||
if (((IGrappleHook) entity).isGrapple()) { | ||
info.setReturnValue(false); | ||
} | ||
} | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "tickFishingLogic", cancellable = true) | ||
public void preventGrappleFishingLogic(BlockPos pos, CallbackInfo info) { | ||
FishingBobberEntity entity = (FishingBobberEntity) (Object) this; | ||
|
||
if (((IGrappleHook) entity).isGrapple()) { | ||
info.cancel(); | ||
} | ||
} | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "use", cancellable = true) | ||
public void preventGrappleFishingUse(ItemStack stack, CallbackInfoReturnable<Integer> info) { | ||
FishingBobberEntity entity = (FishingBobberEntity) (Object) this; | ||
|
||
if (((IGrappleHook) entity).isGrapple()) { | ||
info.setReturnValue(0); | ||
} | ||
} | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "remove", cancellable = true) | ||
public void blockRemoveIfGrappleA(CallbackInfo info) { | ||
FishingBobberEntity entity = (FishingBobberEntity) (Object) this; | ||
|
||
if (((IGrappleHook) entity).isGrapple()) { | ||
previousFishHook = entity.getPlayerOwner().fishHook; | ||
} | ||
} | ||
|
||
@Inject(at = @At(value = "RETURN"), method = "remove", cancellable = true) | ||
public void blockRemoveIfGrappleB(CallbackInfo info) { | ||
FishingBobberEntity entity = (FishingBobberEntity) (Object) this; | ||
|
||
if (((IGrappleHook) entity).isGrapple()) { | ||
entity.getPlayerOwner().fishHook = previousFishHook; | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/github/originsplus/mixin/FollowTargetGoalAccessor.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,15 @@ | ||
package com.github.originsplus.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
|
||
@Mixin(FollowTargetGoal.class) | ||
public interface FollowTargetGoalAccessor { | ||
|
||
@Accessor("targetEntity") | ||
public LivingEntity getTargetEntity(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/github/originsplus/mixin/FollowTargetGoalMixin.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,42 @@ | ||
package com.github.originsplus.mixin; | ||
|
||
import java.util.List; | ||
|
||
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.CallbackInfo; | ||
|
||
import com.github.originsplus.power.ModifyBehavior; | ||
import com.github.originsplus.power.ModifyBehavior.EntityBehavior; | ||
|
||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
|
||
@Mixin(FollowTargetGoal.class) | ||
public class FollowTargetGoalMixin { | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "start", cancellable = true) | ||
public void blockZombieTarget(CallbackInfo info) { | ||
FollowTargetGoal target = (FollowTargetGoal) (Object) this; | ||
|
||
List<ModifyBehavior> powers = OriginComponent.getPowers(((FollowTargetGoalAccessor) target).getTargetEntity(), ModifyBehavior.class); | ||
powers.removeIf((power) -> { | ||
if(power.checkEntity(((TrackTargetGoalAccessor) target).getMob().getType())) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}); | ||
|
||
if (!powers.isEmpty()) { | ||
ModifyBehavior.EntityBehavior behavior = powers.get(0).getDesiredBehavior(); | ||
if(behavior == EntityBehavior.NEUTRAL) { | ||
//System.out.println("Modifying entity behavior"); | ||
target.stop(); | ||
info.cancel(); | ||
} | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/originsplus/mixin/IronGolemEntityMixin.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,63 @@ | ||
package com.github.originsplus.mixin; | ||
|
||
import java.util.List; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import com.github.originsplus.power.ModifyBehavior; | ||
import com.github.originsplus.power.ModifyBehavior.EntityBehavior; | ||
|
||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
import net.minecraft.entity.ai.goal.Goal; | ||
import net.minecraft.entity.ai.goal.GoalSelector; | ||
import net.minecraft.entity.mob.Angerable; | ||
import net.minecraft.entity.passive.GolemEntity; | ||
import net.minecraft.entity.passive.IronGolemEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.world.World; | ||
|
||
@Mixin(IronGolemEntity.class) | ||
public abstract class IronGolemEntityMixin extends GolemEntity implements Angerable { | ||
|
||
IronGolemEntityMixin(EntityType<? extends GolemEntity> entityType, World world) { | ||
super(entityType, world); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/GoalSelector;add(ILnet/minecraft/entity/ai/goal/Goal;)V", ordinal = 9), method = "initGoals") | ||
public void overrideFollowTargetGoalForZombies(GoalSelector goalSelector, int priority, Goal goal) { | ||
Goal newGoal = new FollowTargetGoal(this, PlayerEntity.class, 10, true, false, (entity) -> { | ||
if(entity instanceof LivingEntity) { | ||
LivingEntity player = (LivingEntity) entity; | ||
|
||
List<ModifyBehavior> powers = OriginComponent.getPowers(player, ModifyBehavior.class); | ||
powers.removeIf((power) -> { | ||
return !power.checkEntity(EntityType.IRON_GOLEM); | ||
}); | ||
|
||
boolean zombified = false; | ||
|
||
if(!powers.isEmpty()) { | ||
zombified = powers.get(0).getDesiredBehavior() == EntityBehavior.HOSTILE; | ||
} | ||
|
||
return this.shouldAngerAt(player) || zombified; | ||
} | ||
|
||
return false; | ||
}); | ||
goalSelector.add(priority, newGoal); | ||
} | ||
|
||
// @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/GoalSelector;add(ILnet/minecraft/entity/ai/goal/Goal;)V", ordinal = 8), method = "initGoals") | ||
// private void redirectTargetGoal(GoalSelector goalSelector, int priority, Goal goal) { | ||
// Goal newGoal = new FollowTargetGoal<PlayerEntity>(this, PlayerEntity.class, 10, true, false, e -> !PowerTypes.SCARE_CREEPERS.isActive(e)); | ||
// goalSelector.add(priority, newGoal); | ||
// } | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/originsplus/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,31 @@ | ||
package com.github.originsplus.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.CallbackInfo; | ||
|
||
import com.github.originsplus.power.WaterWalkingPower; | ||
|
||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.enchantment.FrostWalkerEnchantment; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
@Mixin(LivingEntity.class) | ||
public class LivingEntityMixin { | ||
|
||
@Inject(at = @At(value = "HEAD"), method = "applyMovementEffects") | ||
public void updateWaterWalkingPower(BlockPos pos, CallbackInfo info) { | ||
LivingEntity entity = (LivingEntity) (Object) this; | ||
|
||
if(OriginComponent.hasPower(entity, WaterWalkingPower.class)) { | ||
int strength = OriginComponent.getPowers(entity, WaterWalkingPower.class).stream().mapToInt((power) -> { | ||
return power.getStrength(); | ||
}).sorted().findFirst().getAsInt(); | ||
|
||
FrostWalkerEnchantment.freezeWater(entity, entity.world, pos, strength); | ||
} | ||
} | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/github/originsplus/mixin/SnowGolemEntityMixin.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,55 @@ | ||
package com.github.originsplus.mixin; | ||
|
||
import java.util.List; | ||
|
||
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.CallbackInfo; | ||
|
||
import com.github.originsplus.power.ModifyBehavior; | ||
import com.github.originsplus.power.ModifyBehavior.EntityBehavior; | ||
|
||
import io.github.apace100.origins.component.OriginComponent; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.Shearable; | ||
import net.minecraft.entity.ai.RangedAttackMob; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
import net.minecraft.entity.passive.GolemEntity; | ||
import net.minecraft.entity.passive.SnowGolemEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.world.World; | ||
|
||
@Mixin(SnowGolemEntity.class) | ||
public abstract class SnowGolemEntityMixin extends GolemEntity implements Shearable, RangedAttackMob { | ||
|
||
SnowGolemEntityMixin(EntityType<? extends GolemEntity> entityType, World world) { | ||
super(entityType, world); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
@Inject(at = @At(value = "RETURN"), method = "initGoals", cancellable = true) | ||
public void initPlayerZombieGoals(CallbackInfo info) { | ||
this.targetSelector.add(1, new FollowTargetGoal(this, PlayerEntity.class, 10, true, false, (entity) -> { | ||
if(entity instanceof PlayerEntity) { | ||
PlayerEntity player = (PlayerEntity) entity; | ||
List<ModifyBehavior> powers = OriginComponent.getPowers(player, ModifyBehavior.class); | ||
powers.removeIf((power) -> { | ||
if(power.checkEntity(this.getType())) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}); | ||
|
||
if (!powers.isEmpty()) { | ||
ModifyBehavior.EntityBehavior behavior = powers.get(0).getDesiredBehavior(); | ||
if(behavior == EntityBehavior.HOSTILE) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
})); | ||
} | ||
} |
Oops, something went wrong.