Skip to content

Commit

Permalink
I am dumb and let us not speak of it
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Jul 21, 2021
1 parent 2f322c8 commit 91d0307
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 55 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Vivecraft-Spigot-Extensions
version: '1.17.1-a1'
version: '1.17.1-b1'
api-version: 1.17
main: org.vivecraft.VSE
website: http://www.vivecraft.org/
Expand Down
6 changes: 0 additions & 6 deletions src/org/vivecraft/Reflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import net.minecraft.core.DefaultedRegistry;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.target.TargetGoal;
import net.minecraft.world.entity.monster.EnderMan;

public class Reflector {
Expand All @@ -23,9 +20,6 @@ public class Reflector {

public static Method Entity_teleport= getPrivateMethod("t", EnderMan.class);
public static Method Entity_teleportTowards = getPrivateMethod("a", EnderMan.class, Entity.class);
//the spigot remapper borks these so do it with reflection.
public static Method RegistryBlocks_get= getPrivateMethod("get", DefaultedRegistry.class, ResourceLocation.class);
public static Method TargetGoal_getFollowingDistance= getPrivateMethod("k", TargetGoal.class);

public static Object getFieldValue(Field field, Object object) {
try
Expand Down
18 changes: 6 additions & 12 deletions src/org/vivecraft/VSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public Map<String, Integer> call() throws Exception {
} catch (Exception e) {
getLogger().warning("Could not start bStats metrics");
}


// Config Part
config.options().copyDefaults(true);
Expand All @@ -156,18 +155,15 @@ public Map<String, Integer> call() throws Exception {
List<String> temp = sec.getStringList("blocklist");
//make an attempt to validate these on the server for debugging.
if(temp != null){
for (String string : temp) {

if (Reflector.invoke(Reflector.RegistryBlocks_get, net.minecraft.core.Registry.BLOCK, new ResourceLocation(string)) == null) {
for (String string : temp) {
if (net.minecraft.core.Registry.BLOCK.get(new ResourceLocation(string)) == null) {
getLogger().warning("Unknown climbey block name: " + string);
continue;
}

blocklist.add(string);
}
}
}

}
// end Config part

getCommand("vive").setExecutor(new ViveCommand(this));
Expand Down Expand Up @@ -218,9 +214,7 @@ public static ItemStack setLocalizedItemName(ItemStack stack, String key) {
nmsStack.setHoverName(new TextComponent(key));
return CraftItemStack.asBukkitCopy(nmsStack);
}



@EventHandler(priority = EventPriority.MONITOR)
public void onEvent(CreatureSpawnEvent event) {
if(!event.isCancelled()){
Expand Down Expand Up @@ -248,7 +242,7 @@ public void EditEntity(Entity entity){
break;
}
}
((Mob)e).goalSelector.addGoal(2, new CustomGoalSwell(e));
e.goalSelector.addGoal(2, new CustomGoalSwell(e));
}
else if(entity.getType() == EntityType.ENDERMAN){
EnderMan e = ((CraftEnderman) entity).getHandle();
Expand All @@ -259,7 +253,7 @@ else if(entity.getType() == EntityType.ENDERMAN){
break;
}
}
((Mob)e).targetSelector.addGoal(1, new CustomPathFinderGoalPlayerWhoLookedAtTarget(e, e::isAngryAt));
e.targetSelector.addGoal(1, new CustomPathFinderGoalPlayerWhoLookedAtTarget(e, e::isAngryAt));

AbstractCollection<WrappedGoal> goals = (AbstractCollection<WrappedGoal>) Reflector.getFieldValue(Reflector.availableGoals, ((Mob)e).goalSelector);
for(WrappedGoal b: goals){
Expand All @@ -268,7 +262,7 @@ else if(entity.getType() == EntityType.ENDERMAN){
break;
}
}
((Mob)e).goalSelector.addGoal(1, new CustomGoalStare(e));
e.goalSelector.addGoal(1, new CustomGoalStare(e));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/org/vivecraft/VivePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public Vec3 getHMDDir(){
Vector3 forward = new Vector3(0,0,-1);
Quaternion q = new Quaternion(w, x, y, z);
Vector3 out = q.multiply(forward);



//System.out.println("("+out.getX()+","+out.getY()+","+out.getZ()+")" + " : W:" + w + " X: "+x + " Y:" + y+ " Z:" + z);
da.close(); //needed?
return new Vec3(out.getX(), out.getY(), out.getZ());
Expand Down
1 change: 0 additions & 1 deletion src/org/vivecraft/entities/CustomGoalStare.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.vivecraft.VivePlayer;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.monster.EnderMan;
Expand Down
6 changes: 2 additions & 4 deletions src/org/vivecraft/entities/CustomGoalSwell.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import org.vivecraft.VSE;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.monster.Creeper;

Expand All @@ -25,7 +23,7 @@ public CustomGoalSwell(Creeper var0) {
@Override
public boolean canUse(){
VSE vse = (VSE.getPlugin(VSE.class));
LivingEntity livingentity = ((Mob)this.creeper).getTarget();
LivingEntity livingentity = this.creeper.getTarget();
if(vse.getConfig().getBoolean("CreeperRadius.enabled") == true){
if(livingentity != null && VSE.vivePlayers.containsKey(livingentity.getBukkitEntity().getUniqueId()) && VSE.isVive(VSE.vivePlayers.get(livingentity.getBukkitEntity().getUniqueId()).player))
creeperBlowyUppyRadius = vse.getConfig().getDouble("CreeperRadius.radius");
Expand All @@ -37,7 +35,7 @@ public boolean canUse(){
public void start()
{
this.creeper.getNavigation().stop();
this.target = ((Mob)this.creeper).getTarget();
this.target = this.creeper.getTarget();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.EntityGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

public class CustomPathFinderGoalPlayerWhoLookedAtTarget extends NearestAttackableTargetGoal<Player> {
private final Entity enderman;
private Entity pendingTarget;
private final EnderMan enderman;
private Player pendingTarget;
private int aggroTime;
private int teleportTime;
private final TargetingConditions startAggroTargetConditions;
Expand All @@ -33,7 +30,7 @@ public class CustomPathFinderGoalPlayerWhoLookedAtTarget extends NearestAttackab
public CustomPathFinderGoalPlayerWhoLookedAtTarget(EnderMan entityenderman, Predicate<LivingEntity> p) {
super(entityenderman, Player.class, 10, false, false, p);
this.enderman = entityenderman;
this.startAggroTargetConditions = TargetingConditions.forCombat().range((double) Reflector.invoke(Reflector.TargetGoal_getFollowingDistance, this)).selector((player) ->
this.startAggroTargetConditions = TargetingConditions.forCombat().range(this.getFollowDistance()).selector((player) ->
{
return isLookingAtMe((Player)player);
});
Expand All @@ -42,7 +39,7 @@ public CustomPathFinderGoalPlayerWhoLookedAtTarget(EnderMan entityenderman, Pred
@Override
public boolean canUse()
{
this.pendingTarget = ((EntityGetter)((Entity)this.enderman).level).getNearestPlayer(this.startAggroTargetConditions, (LivingEntity)this.enderman);
this.pendingTarget = this.enderman.level.getNearestPlayer(this.startAggroTargetConditions, this.enderman);
return this.pendingTarget != null;
}

Expand All @@ -51,7 +48,7 @@ public void start()
{
this.aggroTime = 5;
this.teleportTime = 0;
((EnderMan) this.enderman).setBeingStaredAt();
this.enderman.setBeingStaredAt();
}

@Override
Expand All @@ -62,11 +59,11 @@ public void stop()
}

//Vivecraft copy and modify from EnderMan
private boolean isLookingAtMe(Entity pPlayer)
private boolean isLookingAtMe(Player pPlayer)
{
ItemStack itemstack = ((Player) pPlayer).getInventory().armor.get(3);
ItemStack itemstack = pPlayer.getInventory().armor.get(3);

if (itemstack.is(((Block)Blocks.CARVED_PUMPKIN).asItem()))
if (itemstack.is(Blocks.CARVED_PUMPKIN.asItem()))
{
return false;
}
Expand Down Expand Up @@ -94,7 +91,7 @@ private boolean isLookingAtMe(Entity pPlayer)
if(vr)
return hasLineOfSight(hmdpos, enderman);
else
return ((LivingEntity) pPlayer).hasLineOfSight(enderman);
return pPlayer.hasLineOfSight(enderman);
//
}
}
Expand Down Expand Up @@ -126,7 +123,7 @@ public boolean canContinueToUse()
}
else
{
((EnderMan)this.enderman).lookAt(this.pendingTarget, 10.0F, 10.0F);
this.enderman.lookAt(this.pendingTarget, 10.0F, 10.0F);
return true;
}
}
Expand All @@ -139,7 +136,7 @@ public boolean canContinueToUse()
@Override
public void tick()
{
if (((Mob)this.enderman).getTarget() == null)
if (this.enderman.getTarget() == null)
{
super.setTarget((LivingEntity)null);
}
Expand Down
19 changes: 8 additions & 11 deletions src/org/vivecraft/utils/AimFixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
import net.minecraft.server.RunningOnDifferentThreadException;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;

Expand All @@ -32,25 +29,25 @@ public AimFixHandler(Connection netManager) {

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Entity player = ((ServerGamePacketListenerImpl)netManager.getPacketListener()).player;
Player player = ((ServerGamePacketListenerImpl)netManager.getPacketListener()).player;
boolean isCapturedPacket = msg instanceof ServerboundUseItemPacket || msg instanceof ServerboundUseItemOnPacket || msg instanceof ServerboundPlayerActionPacket;
UUID uuid = ((Player) player).getGameProfile().getId();
UUID uuid = player.getGameProfile().getId();
if (!VSE.vivePlayers.containsKey(uuid) || !VSE.vivePlayers.get(uuid).isVR() || !isCapturedPacket || player.getServer() == null) {
// we don't need to handle this packet, just defer to the next handler in the pipeline
ctx.fireChannelRead(msg);
return;
}

((BlockableEventLoop)player.getServer()).submit(() -> {
player.getServer().submit(() -> {
// Save all the current orientation data
Vec3 oldPos = player.position();
Vec3 oldPrevPos = new Vec3(player.xo, player.yo, player.zo);
float oldPitch = player.getXRot();
float oldYaw = player.getYRot();
float oldYawHead = ((LivingEntity)player).yHeadRot; // field_70759_as
float oldYawHead = player.yHeadRot; // field_70759_as
float oldPrevPitch = player.xRotO;
float oldPrevYaw = player.yRotO;
float oldPrevYawHead = ((LivingEntity)player).yHeadRotO; // field_70758_at
float oldPrevYawHead = player.yHeadRotO; // field_70758_at
float oldEyeHeight = player.getEyeHeight();

VivePlayer data = null;
Expand All @@ -67,7 +64,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
player.setXRot((float)Math.toDegrees(Math.asin(-aim.y)));
player.setYRot((float)Math.toDegrees(Math.atan2(-aim.x, aim.z)));
player.xRotO = player.getXRot();
player.yRotO = ((LivingEntity)player).yHeadRotO = ((LivingEntity)player).yHeadRot = player.getYRot();
player.yRotO = player.yHeadRotO = player.yHeadRot = player.getYRot();
Reflector.setFieldValue(Reflector.Entity_eyesHeight, player, 0);

// Set up offset to fix relative positions
Expand Down Expand Up @@ -99,10 +96,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
player.zo = oldPrevPos.z;
player.setXRot(oldPitch);
player.setYRot(oldYaw);
((LivingEntity)player).yHeadRot = oldYawHead;
player.yHeadRot = oldYawHead;
player.xRotO = oldPrevPitch;
player.yRotO = oldPrevYaw;
((LivingEntity)player).yHeadRotO = oldPrevYawHead;
player.yHeadRotO = oldPrevYawHead;
Reflector.setFieldValue(Reflector.Entity_eyesHeight, player, oldEyeHeight);

// Reset offset
Expand Down
5 changes: 2 additions & 3 deletions src/org/vivecraft/utils/PoseOverrider.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.vivecraft.Reflector;
import org.vivecraft.VSE;
Expand All @@ -16,11 +15,11 @@

public class PoseOverrider {
@SuppressWarnings("unchecked")
public static void injectPlayer(Entity player) {
public static void injectPlayer(Player player) {
EntityDataAccessor<Pose> poseObj = (EntityDataAccessor<Pose>) Reflector.getFieldValue(Reflector.Entity_Data_Pose, player);
SynchedEntityData dataWatcher = ((CraftEntity) player).getHandle().getEntityData();
Int2ObjectOpenHashMap<SynchedEntityData.DataItem<?>> entries = (Int2ObjectOpenHashMap<DataItem<?>>) Reflector.getFieldValue(Reflector.SynchedEntityData_itemsById, dataWatcher);
InjectedDataWatcherItem item = new InjectedDataWatcherItem(poseObj, Pose.STANDING, (Player)player);
InjectedDataWatcherItem item = new InjectedDataWatcherItem(poseObj, Pose.STANDING, player);
entries.put(poseObj.getId(), item);
}

Expand Down
3 changes: 2 additions & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#this file is used to check for updates
1.17.1-a1: VSE is up to date.
1.17.1-a1: VSE has a new version available.
1.17.1-b1: VSE is up to date.

0 comments on commit 91d0307

Please sign in to comment.