All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.mostlyoriginal.api.operation.basic.UnpooledMirrorOperation Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package net.mostlyoriginal.api.operation.basic;

import com.artemis.Component;
import com.artemis.Entity;
import net.mostlyoriginal.api.component.Schedule;
import net.mostlyoriginal.api.component.common.Mirrorable;
import net.mostlyoriginal.api.component.common.Tweenable;
import net.mostlyoriginal.api.operation.common.BasicOperation;
import net.mostlyoriginal.api.plugin.extendedcomponentmapper.M;
import net.mostlyoriginal.api.utils.Preconditions;

/**
 * Set component state.
 *
 * Will create component if missing.
 *
 * Target state is not pooled, and will be garbage collected.
 *
 * For performance reasons it is best to subclass
 * {@see SetOperation} to manage state.
 *
 * @author Daan van Yperen
 * @see Tweenable
 * @see Schedule
 */
public final class UnpooledMirrorOperation extends BasicOperation {

	protected Component a;

	@Override
	@SuppressWarnings("unchecked")
	public void process(Entity e) {
		final M m = M.getFor(a.getClass(),e.getWorld());
		((Mirrorable)m.create(e)).set(a);
	}

	/**
	 * Set target state.
	 *
	 * @param a             component state.
	 */
	public > void setup(T a) {
		this.a = Preconditions.checkNotNull(a);
	}

	@Override
	public void reset() {
		super.reset();
		a = null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy