mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
More AI fixes for inverted entities
This commit is contained in:
parent
b0c621b4b6
commit
bd74a03b8b
6 changed files with 74 additions and 24 deletions
|
@ -1,17 +1,23 @@
|
||||||
package com.minelittlepony.unicopia.entity;
|
package com.minelittlepony.unicopia.entity;
|
||||||
|
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public interface RotatedView {
|
public interface RotatedView {
|
||||||
|
|
||||||
void setRotationCenter(int y, int increments);
|
Stack<Integer> getRotations();
|
||||||
|
|
||||||
int getRotationY();
|
boolean hasTransform();
|
||||||
|
|
||||||
int getRotationIncrements();
|
default void pushRotation(int y) {
|
||||||
|
getRotations().add(y);
|
||||||
|
}
|
||||||
|
|
||||||
default void clearRotation() {
|
default void popRotation() {
|
||||||
setRotationCenter(0, 0);
|
if (!getRotations().isEmpty()) {
|
||||||
|
getRotations().pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default BlockPos applyRotation(BlockPos pos) {
|
default BlockPos applyRotation(BlockPos pos) {
|
||||||
|
@ -19,14 +25,14 @@ public interface RotatedView {
|
||||||
if (newY == pos.getY()) {
|
if (newY == pos.getY()) {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
return new BlockPos(pos.getX(), applyRotation(pos.getY()), pos.getZ());
|
return new BlockPos(pos.getX(), newY, pos.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
default int applyRotation(int y) {
|
default int applyRotation(int y) {
|
||||||
if (getRotationIncrements() == 0) {
|
if (!hasTransform() || getRotations().isEmpty()) {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
return y - ((y - getRotationY()) * 2);
|
return y - ((y - getRotations().peek()) * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.minelittlepony.unicopia.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.minelittlepony.unicopia.entity.RotatedView;
|
||||||
|
import com.minelittlepony.unicopia.entity.Equine;
|
||||||
|
import com.minelittlepony.unicopia.entity.Living;
|
||||||
|
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.ai.brain.Brain;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
|
||||||
|
@Mixin(Brain.class)
|
||||||
|
abstract class MixinBrain<E extends LivingEntity> {
|
||||||
|
|
||||||
|
@Inject(method = "tick", at = @At("HEAD"))
|
||||||
|
public void beforeTickAi(ServerWorld world, E entity, CallbackInfo into) {
|
||||||
|
Equine<?> eq = Equine.of(entity);
|
||||||
|
|
||||||
|
if (eq instanceof Living<?> && eq.getPhysics().isGravityNegative()) {
|
||||||
|
((RotatedView)world).pushRotation((int)entity.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "tick", at = @At("RETURN"))
|
||||||
|
public void afterTickAi(ServerWorld world, E entity, CallbackInfo into) {
|
||||||
|
((RotatedView)world).popRotation();
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,12 +37,12 @@ abstract class MixinMobEntity extends LivingEntity implements PonyContainer<Equi
|
||||||
Equine<?> eq = Equine.of(this);
|
Equine<?> eq = Equine.of(this);
|
||||||
|
|
||||||
if (eq instanceof Living<?> && eq.getPhysics().isGravityNegative()) {
|
if (eq instanceof Living<?> && eq.getPhysics().isGravityNegative()) {
|
||||||
((RotatedView)world).setRotationCenter((int)getY(), 1);
|
((RotatedView)world).pushRotation((int)getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "tickNewAi", at = @At("RETURN"))
|
@Inject(method = "tickNewAi", at = @At("RETURN"))
|
||||||
public void afterTickAi(CallbackInfo into) {
|
public void afterTickAi(CallbackInfo into) {
|
||||||
((RotatedView)world).clearRotation();
|
((RotatedView)world).popRotation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
package com.minelittlepony.unicopia.mixin;
|
package com.minelittlepony.unicopia.mixin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.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.ModifyVariable;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.BlockDestructionManager;
|
import com.minelittlepony.unicopia.BlockDestructionManager;
|
||||||
import com.minelittlepony.unicopia.entity.RotatedView;
|
import com.minelittlepony.unicopia.entity.RotatedView;
|
||||||
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
|
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -23,26 +30,19 @@ abstract class MixinWorld implements WorldAccess, BlockDestructionManager.Source
|
||||||
|
|
||||||
private final BlockDestructionManager destructions = new BlockDestructionManager((World)(Object)this);
|
private final BlockDestructionManager destructions = new BlockDestructionManager((World)(Object)this);
|
||||||
|
|
||||||
private int rotationY;
|
private int recurseCount = 0;
|
||||||
private int rotationIncrements;
|
private Stack<Integer> rotations = new Stack<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRotationCenter(int y, int increments) {
|
public Stack<Integer> getRotations() {
|
||||||
rotationY = y;
|
return rotations;
|
||||||
rotationIncrements = increments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRotationY() {
|
public boolean hasTransform() {
|
||||||
return rotationY;
|
return recurseCount <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRotationIncrements() {
|
|
||||||
return rotationIncrements;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockDestructionManager getDestructionManager() {
|
public BlockDestructionManager getDestructionManager() {
|
||||||
return destructions;
|
return destructions;
|
||||||
|
@ -59,4 +59,16 @@ abstract class MixinWorld implements WorldAccess, BlockDestructionManager.Source
|
||||||
|
|
||||||
return WorldAccess.super.getEntityCollisions(entity, box, predicate);
|
return WorldAccess.super.getEntityCollisions(entity, box, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModifyVariable(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD"))
|
||||||
|
private BlockPos modifyBlockPos(BlockPos pos) {
|
||||||
|
pos = applyRotation(pos);
|
||||||
|
recurseCount = Math.max(0, recurseCount) + 1;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("RETURN"))
|
||||||
|
public void onSetBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> info) {
|
||||||
|
recurseCount = Math.max(0, recurseCount - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ abstract class MixinWorldChunk {
|
||||||
|
|
||||||
@ModifyVariable(method = {
|
@ModifyVariable(method = {
|
||||||
"getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;",
|
"getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;",
|
||||||
"setBlockState(Lnet/minecraft/util/math/BlockPos;)V",
|
"setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/block/BlockState;",
|
||||||
"getBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/chunk/WorldChunk$CreationType;)Lnet/minecraft/block/entity/BlockEntity;",
|
"getBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/chunk/WorldChunk$CreationType;)Lnet/minecraft/block/entity/BlockEntity;",
|
||||||
"setBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;)V",
|
"setBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;)V",
|
||||||
"removeBlockEntity(Lnet/minecraft/util/math/BlockPos;)V",
|
"removeBlockEntity(Lnet/minecraft/util/math/BlockPos;)V",
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinBlockEntity",
|
"MixinBlockEntity",
|
||||||
"MixinBlockItem",
|
"MixinBlockItem",
|
||||||
|
"MixinBrain",
|
||||||
"MixinFallingBlock",
|
"MixinFallingBlock",
|
||||||
"MixinItem",
|
"MixinItem",
|
||||||
"MixinItemEntity",
|
"MixinItemEntity",
|
||||||
|
|
Loading…
Reference in a new issue