use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeForge by SpongePowered.
the class MixinLoader method discoverMods.
@Redirect(method = "identifyMods", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/discovery/ModDiscoverer;findModDirMods(Ljava/io/File;[Ljava/io/File;)V", remap = false))
private void discoverMods(ModDiscoverer modDiscoverer, File modsDir, File[] additionalMods) {
modDiscoverer.findModDirMods(modsDir, additionalMods);
File pluginsDir = this.getPluginsDir();
if (pluginsDir.isDirectory() && !pluginsDir.equals(modsDir)) {
FMLLog.info("Searching %s for plugins", pluginsDir.getAbsolutePath());
this.discoverPlugins(modDiscoverer, pluginsDir);
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeForge by SpongePowered.
the class MixinEventBus method onUnregisterListener.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Redirect(method = "unregister", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/ListenerList;unregisterAll(ILnet/minecraftforge/fml/common/eventhandler/IEventListener;)V", remap = false))
public void onUnregisterListener(int id, IEventListener listener) {
ListenerList.unregisterAll(id, listener);
SpongeModEventManager manager = ((SpongeModEventManager) SpongeImpl.getGame().getEventManager());
for (Class clazz : TypeToken.of(checkNotNull(this.forgeListenerRegistry.remove(listener))).getTypes().rawTypes()) {
Collection<Class<? extends org.spongepowered.api.event.Event>> spongeEvents = manager.forgeToSpongeEventMapping.get(clazz);
if (spongeEvents != null) {
for (Class<? extends org.spongepowered.api.event.Event> event : spongeEvents) {
manager.checker.unregisterListenerFor(event);
}
}
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeVanilla by SpongePowered.
the class MixinAdvancementManager method onLoadAdvancements.
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementList;loadAdvancements(Ljava/util/Map;)V"))
private void onLoadAdvancements(AdvancementList advancementList, Map<ResourceLocation, Advancement.Builder> advancements) {
if (!SpongeImpl.isInitialized()) {
return;
}
for (PluginContainer pluginContainer : Sponge.getPluginManager().getPlugins()) {
// Skip the minecraft advancements
if (pluginContainer.getId().equals("minecraft")) {
continue;
}
final Optional<Path> optSource = pluginContainer.getSource();
if (optSource.isPresent()) {
final Path source = optSource.get();
final String base = "assets/" + pluginContainer.getId() + "/advancements";
Path root;
if (Files.isDirectory(source)) {
root = source.resolve(base);
} else {
try {
final FileSystem fileSystem = FileSystems.newFileSystem(source, null);
root = fileSystem.getPath("/" + base);
} catch (IOException e) {
SpongeImpl.getLogger().error("Error loading FileSystem from jar: ", e);
continue;
}
}
if (!Files.exists(root)) {
continue;
}
try {
Files.walk(root).forEach(path -> {
if (!FilenameUtils.getExtension(path.getFileName().toString()).equals("json")) {
return;
}
final Path relPath = root.relativize(path);
final String id = FilenameUtils.removeExtension(relPath.toString()).replaceAll("\\\\", "/");
final ResourceLocation resourceLocation = new ResourceLocation(pluginContainer.getId(), id);
if (!advancements.containsKey(resourceLocation)) {
try (BufferedReader reader = Files.newBufferedReader(path)) {
final Advancement.Builder advancementBuilder = JsonUtils.fromJson(GSON, reader, Advancement.Builder.class);
advancements.put(resourceLocation, advancementBuilder);
} catch (IOException e) {
SpongeImpl.getLogger().error("Failed to read advancement " + resourceLocation + " from path " + path, e);
}
}
});
} catch (IOException e) {
SpongeImpl.getLogger().error("Failed to walk path: " + root, e);
}
}
}
advancementList.loadAdvancements(advancements);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeVanilla by SpongePowered.
the class MixinEntityLivingBase method onSetHeldItem.
@Redirect(method = "onItemUseFinish", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;" + "setHeldItem(Lnet/minecraft/util/EnumHand;Lnet/minecraft/item/ItemStack;)V"))
private void onSetHeldItem(EntityLivingBase self, EnumHand hand, @Nullable ItemStack stack) {
ItemStackSnapshot activeItemStackSnapshot = ItemStackUtil.snapshotOf(this.activeItemStack);
Sponge.getCauseStackManager().pushCause(this);
UseItemStackEvent.Replace event = SpongeEventFactory.createUseItemStackEventReplace(Sponge.getCauseStackManager().getCurrentCause(), this.activeItemStackUseCount, this.activeItemStackUseCount, activeItemStackSnapshot, new Transaction<>(activeItemStackSnapshot, ItemStackUtil.snapshotOf(stack)));
if (SpongeImpl.postEvent(event)) {
Sponge.getCauseStackManager().popCause();
// Don't touch the held item if event is cancelled
return;
}
Sponge.getCauseStackManager().popCause();
if (!event.getItemStackResult().isValid()) {
return;
}
setHeldItem(hand, ItemStackUtil.fromSnapshotToNative(event.getItemStackResult().getFinal()));
}
use of org.spongepowered.asm.mixin.injection.Redirect in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksForGetBlockDensity.
/**
* Use Bresenham's tracing algorithm instead of raytracing for getBlockDensity, makes it way faster
*/
@Redirect(method = "getBlockDensity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
private RayTraceResult rayTraceBlocksForGetBlockDensity(World world, Vec3d start, Vec3d end) {
if (VSConfig.explosionMode == ExplosionMode.VANILLA) {
// Vanilla raytrace, ignore ships and perform the function like normal
this.shouldInterceptRayTrace = false;
RayTraceResult result = rayTraceBlocks(start, end);
this.shouldInterceptRayTrace = true;
return result;
} else if (VSConfig.explosionMode == ExplosionMode.SLOW_VANILLA) {
// Vanilla raytrace, include ships and perform the function like normal
return rayTraceBlocks(start, end);
}
java.util.function.Predicate<BlockPos> canCollide = pos -> {
IBlockState blockState = world.getBlockState(pos);
return blockState.getBlock().canCollideCheck(blockState, false);
};
// Get all the blocks between start and end
List<BlockPos> blocks = VSMath.generateLineBetween(start, end, BlockPos::new);
// Whether or not this ray trace hit a block that was collidable.
boolean collided = blocks.stream().anyMatch(canCollide);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld != null) {
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(new AxisAlignedBB(start.x, start.y, start.z, end.x, end.y, end.z));
for (PhysicsObject obj : nearbyShips) {
Vec3d transformedStart = obj.transformVector(start, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d transformedEnd = obj.transformVector(end, TransformType.GLOBAL_TO_SUBSPACE);
// Transform the raytrace into ship space and check whether or not it hit a block
List<BlockPos> physoBlocks = VSMath.generateLineBetween(transformedStart, transformedEnd, BlockPos::new);
collided |= physoBlocks.stream().anyMatch(canCollide);
}
}
// important information in the ray trace result.
return collided ? DUMMY_RAYTRACE_RESULT : null;
}
Aggregations