Skip to content

Commit

Permalink
Merge pull request #526 from DSH105/MC-184
Browse files Browse the repository at this point in the history
MC 1.8.4
  • Loading branch information
DSH105 committed May 22, 2015
2 parents 26ac4a6 + df95f0b commit 26c3c42
Show file tree
Hide file tree
Showing 42 changed files with 4,037 additions and 1 deletion.
96 changes: 96 additions & 0 deletions modules/v1_8_R3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!--
~ This file is part of EchoPet.
~
~ EchoPet is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ EchoPet is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>EchoPet-v1_8_R3</artifactId>
<name>EchoPet for v1_8_R3</name>
<version>v2</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
<groupId>com.dsh105</groupId>
<artifactId>EchoPet-Parent</artifactId>
<version>v2</version>
<relativePath>../../</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.4-R0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.4-R0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.dsh105</groupId>
<artifactId>EchoPet-API</artifactId>
<version>v2</version>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<directory>../../target</directory>
<sourceDirectory>src/main/java/</sourceDirectory>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
<version>2.5</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.compat.nms.v1_8_R3;

import com.captainbern.minecraft.reflection.MinecraftReflection;
import com.captainbern.reflection.ClassTemplate;
import com.captainbern.reflection.Reflection;
import com.captainbern.reflection.SafeField;
import com.captainbern.reflection.SafeMethod;
import com.captainbern.reflection.accessor.FieldAccessor;
import com.captainbern.reflection.accessor.MethodAccessor;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.entity.LivingEntity;

import java.util.List;

import static com.captainbern.reflection.matcher.Matchers.withArguments;
import static com.captainbern.reflection.matcher.Matchers.withType;

/*
* From EntityAPI :)
*/

public class NMSEntityUtil {

public static NavigationAbstract getNavigation(LivingEntity livingEntity) {
if (livingEntity instanceof CraftLivingEntity) {
return getNavigation(((CraftLivingEntity) livingEntity).getHandle());
}
return null;
}

public static NavigationAbstract getNavigation(EntityLiving entityLiving) {
if (entityLiving instanceof EntityInsentient) {
return ((EntityInsentient) entityLiving).getNavigation();
}
return null;
}

public static EntitySenses getEntitySenses(LivingEntity livingEntity) {
if (livingEntity instanceof CraftLivingEntity) {
return getEntitySenses(((CraftLivingEntity) livingEntity).getHandle());
}
return null;
}

public static EntitySenses getEntitySenses(EntityLiving entityLiving) {
if (entityLiving instanceof EntityInsentient) {
return ((EntityInsentient) entityLiving).getEntitySenses();
}
return null;
}

public static ControllerJump getControllerJump(LivingEntity livingEntity) {
if (livingEntity instanceof CraftLivingEntity) {
return getControllerJump(((CraftLivingEntity) livingEntity).getHandle());
}
return null;
}

public static ControllerJump getControllerJump(EntityLiving entityLiving) {
if (entityLiving instanceof EntityInsentient) {
return ((EntityInsentient) entityLiving).getControllerJump();
}
return null;
}

public static ControllerMove getControllerMove(LivingEntity livingEntity) {
if (livingEntity instanceof CraftLivingEntity) {
return getControllerMove(((CraftLivingEntity) livingEntity).getHandle());
}
return null;
}

public static ControllerMove getControllerMove(EntityLiving entityLiving) {
if (entityLiving instanceof EntityInsentient) {
return ((EntityInsentient) entityLiving).getControllerMove();
}
return null;
}

public static ControllerLook getControllerLook(LivingEntity livingEntity) {
if (livingEntity instanceof CraftLivingEntity) {
return getControllerLook(((CraftLivingEntity) livingEntity).getHandle());
}
return null;
}

public static ControllerLook getControllerLook(EntityLiving entityLiving) {
if (entityLiving instanceof EntityInsentient) {
return ((EntityInsentient) entityLiving).getControllerLook();
}
return null;
}

public static boolean isInGuardedAreaOf(EntityLiving entityLiving, int x, int y, int z) {
// TODO: not used currently
return false;
/*if (entityLiving instanceof EntityCreature) {
return ((EntityCreature) entityLiving).d(new BlockPosition(x, y, z));
} else {
return false;
}*/
}

/*
* Hacky stuff to get around doTick() becoming final
*/

protected static FieldAccessor<List> GOALS;
protected static FieldAccessor<List> ACTIVE_GOALS;

protected static MethodAccessor<Void> ADD_GOAL;

protected static FieldAccessor<Object> GOAL_SELECTOR;

public static void clearGoals(Object nmsEntityHandle) {
if (GOALS == null || ACTIVE_GOALS == null || GOAL_SELECTOR == null) {
initializeFields();
}

GOALS.get(GOAL_SELECTOR.get(nmsEntityHandle)).clear();
ACTIVE_GOALS.get(GOAL_SELECTOR.get(nmsEntityHandle)).clear();
}

protected static void initializeFields() {
try {

ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
if (methodCandidates.size() > 0) {
ADD_GOAL = methodCandidates.get(0).getAccessor();
} else {
throw new RuntimeException("Failed to get the addGoal method!");
}

List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
if (fieldCandidates.size() > 1) {
GOALS = fieldCandidates.get(0).getAccessor();
ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
} else {
throw new RuntimeException("Failed to initialize the goal-lists!");
}

// The GoalSelector
ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

if (candidates.size() > 0) {
GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
} else {
throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
}

} catch (Exception ಠ_ಠ) {
throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.compat.nms.v1_8_R3;

import com.dsh105.commodus.particle.Particle;
import com.dsh105.echopet.compat.api.entity.IPet;
import com.dsh105.echopet.compat.api.event.PetPreSpawnEvent;
import com.dsh105.echopet.compat.api.plugin.EchoPet;
import com.dsh105.echopet.compat.api.util.ISpawnUtil;
import com.dsh105.echopet.compat.nms.v1_8_R3.entity.EntityPet;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;

public class SpawnUtil implements ISpawnUtil {

@Override
public EntityPet spawn(IPet pet, Player owner) {
Location l = owner.getLocation();
PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
if (spawnEvent.isCancelled()) {
owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
EchoPet.getManager().removePet(pet, true);
return null;
}
l = spawnEvent.getSpawnLocation();
World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
if (!l.getChunk().isLoaded()) {
l.getChunk().load();
}
if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
EchoPet.getManager().removePet(pet, true);
} else {
Particle.MAGIC_RUNES.builder().at(l).show();
}
return entityPet;
}
}
Loading

0 comments on commit 26c3c42

Please sign in to comment.