Skip to content

Commit

Permalink
Almost ready for the first release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lochnessdragon committed Mar 16, 2021
1 parent 07e85f9 commit 223dab6
Show file tree
Hide file tree
Showing 36 changed files with 720 additions and 138 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/github/originsplus/OriginsPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.entity.mob.ZombieVillagerEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.thrown.SnowballEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
Expand Down Expand Up @@ -65,6 +66,7 @@ public void onInitialize() {
serverWorld.syncWorldEvent((PlayerEntity) null, 1026, player.getBlockPos(), 0);
}
}

}

return ActionResult.PASS;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/github/originsplus/entity/IGrappleHook.java
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);

}
16 changes: 9 additions & 7 deletions src/main/java/com/github/originsplus/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

@Mixin(Block.class)
public class BlockMixin {

@Inject(at = @At(value = "HEAD"), method = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V", cancellable = true)
public void onStacksDropped(final World world, final BlockPos pos, final BlockState state, final PlayerEntity player, final CallbackInfo info) {
ActionResult result = BlockDropCallback.EVENT.invoker().onBreak((Block) (Object) this, state, world, pos, player);

if(result == ActionResult.FAIL) {
info.cancel();
}
public void onStacksDropped(final World world, final BlockPos pos, final BlockState state,
final PlayerEntity player, final CallbackInfo info) {
ActionResult result = BlockDropCallback.EVENT.invoker().onBreak((Block) (Object) this, state, world, pos,
player);

if (result == ActionResult.FAIL) {
info.cancel();
}
}
}
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;
}
}

}
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();

}
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();
}
}
}

}
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 src/main/java/com/github/originsplus/mixin/LivingEntityMixin.java
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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void increaseSpawnRate(CallbackInfo info) {
}
}
}

//System.out.println("Spawn Count was: " + logicAccessor.getSpawnCount() + " and is now: " + spawnCount);
logicAccessor.setSpawnCount(spawnCount);
}

Expand Down
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;
}));
}
}
Loading

0 comments on commit 223dab6

Please sign in to comment.