Update Buildcraft API

This commit is contained in:
Nedelosk committed 2016-04-29 21:11:45 +02:00
1 parent eba8fb8c69
commit 5e75430526
21 files changed
+194 -109

No files matched your search

@@ -6,7 +6,6 @@ package buildcraft.api.blueprints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map.Entry;
@@ -407,16 +406,19 @@ public class MappingRegistry {
}
public void addToCrashReport(CrashReportCategory cat) {
Comparator<Entry<?, Integer>> comparator = (e1, e2) -> e1.getValue() - e2.getValue();
cat.addCrashSection("Item Map Count", itemToId.size());
itemToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), Item.itemRegistry.getNameForObject(
e.getKey())));
for (Entry<Item, Integer> e : itemToId.entrySet()) {
cat.addCrashSection(" - ID " + e.getValue(), Item.itemRegistry.getNameForObject(e.getKey()));
}
cat.addCrashSection("Block Map Count", blockToId.size());
blockToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey()));
for (Entry<Block, Integer> e : blockToId.entrySet()) {
cat.addCrashSection(" - ID " + e.getValue(), Block.blockRegistry.getNameForObject(e.getKey()));
}
cat.addCrashSection("Entity Map Count", entityToId.size());
entityToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey()));
for (Entry<Class<? extends Entity>, Integer> e : entityToId.entrySet()) {
cat.addCrashSection(" - ID " + e.getValue(), e.getKey());
}
}
}
@@ -1,17 +1,15 @@
package buildcraft.api.core;
import java.util.Locale;
import java.util.Map;
import com.google.common.collect.Maps;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import io.netty.buffer.ByteBuf;
import java.util.Locale;
import java.util.Map;
public enum EnumPipePart implements IStringSerializable,INetworkLoadable_BC8<EnumPipePart> {
DOWN(EnumFacing.DOWN),
@@ -36,6 +34,10 @@ public enum EnumPipePart implements IStringSerializable,INetworkLoadable_BC8<Enu
}
}
public static int ordinal(EnumFacing face) {
return face == null ? 6 : face.ordinal();
}
public static EnumPipePart fromFacing(EnumFacing face) {
if (face == null) return EnumPipePart.CENTER;
return facingMap.get(face);
@@ -2,7 +2,8 @@ package buildcraft.api.core;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
import com.google.common.base.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
@@ -24,8 +25,18 @@ public abstract class Identifier {
private static Map<String, Supplier<Identifier>> registeredIdentifiers;
static {
registeredIdentifiers.put("mincraft:tile", () -> new Tile(0, null));
registeredIdentifiers.put("mincraft:entity", () -> new MovableEntity(0, null));
registeredIdentifiers.put("mincraft:tile", new Supplier<Identifier>() {
@Override
public Identifier get() {
return new Tile(0, null);
}
});
registeredIdentifiers.put("mincraft:entity", new Supplier<Identifier>() {
@Override
public Identifier get() {
return new MovableEntity(0, null);
}
});
}
protected final int dimId;
@@ -161,18 +172,27 @@ public abstract class Identifier {
this.uniqueId = uniqueId;
}
private Entity get(World world) {
for (Entity entity : world.loadedEntityList) {
if (entity.getPersistentID().equals(uniqueId)) {
return entity;
}
}
return null;
}
@Override
public Entity getByIdentifier(MinecraftServer server) {
World world = server.worldServerForDimension(dimId);
if (world == null || world.provider.getDimensionId() != dimId) return null;
return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null);
return get(world);
}
@Override
public boolean isLoaded(MinecraftServer server) {
World world = server.worldServerForDimension(dimId);
if (world == null || world.provider.getDimensionId() != dimId) return false;
return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null;
return get(world) != null;
}
@Override
@@ -180,7 +200,7 @@ public abstract class Identifier {
public Entity getByIdentifierClient() {
World world = Minecraft.getMinecraft().theWorld;
if (world == null || world.provider.getDimensionId() != dimId) return null;
return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null);
return get(world);
}
@Override
@@ -188,7 +208,7 @@ public abstract class Identifier {
public boolean isLoadedClient() {
World world = Minecraft.getMinecraft().theWorld;
if (world == null || world.provider.getDimensionId() != dimId) return false;
return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null;
return get(world) != null;
}
@Override
@@ -2,7 +2,7 @@
*
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
@API(apiVersion = "2.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core")
@API(apiVersion = "2.1", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core")
package buildcraft.api.core;
import net.minecraftforge.fml.common.API;
@@ -7,29 +7,21 @@ package buildcraft.api.fuels;
import java.util.Collection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
public interface IFuelManager {
IFuel addFuel(IFuel fuel);
IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime);
// IFuel addFuel(FluidStack fuel, int rfPerBucket, int burnTimePerBucket);
// IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue);
IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue);
Collection<IFuel> getFuels();
IFuel getFuel(Fluid fluid);
// TODO!
// public interface IFuel {
// FluidStack getFuelIngrediant();
//
// int rfPerBucket();
//
// int burnTimePerBucket();
// }
//
// public interface IDirtyFuel extends IFuel {
// FluidStack getResidue();
// }
public interface IDirtyFuel extends IFuel {
/** @return The residue fluidstack, per bucket of original fuel. */
FluidStack getResidue();
}
}
@@ -0,0 +1,36 @@
package buildcraft.api.gates;
import java.util.Arrays;
import net.minecraft.util.EnumWorldBlockLayer;
public class GateExpansionModelKey<K extends GateExpansionModelKey<K>> {
public final EnumWorldBlockLayer layer;
public final IExpansionBaker<K> baker;
private final int hash;
public GateExpansionModelKey(EnumWorldBlockLayer layer, IExpansionBaker<K> baker) {
if (layer != EnumWorldBlockLayer.CUTOUT && layer != EnumWorldBlockLayer.TRANSLUCENT) {
throw new IllegalArgumentException("Unsuported layer! Was " + layer + ", wanted CUTOUT or TRANSLUCENT");
}
if (baker == null) throw new NullPointerException("baker");
this.layer = layer;
this.baker = baker;
hash = Arrays.hashCode(new int[] { layer.hashCode(), System.identityHashCode(baker) });
}
@Override
public int hashCode() {
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
GateExpansionModelKey<?> other = (GateExpansionModelKey<?>) obj;
if (baker != other.baker) return false;
return true;
}
}
@@ -0,0 +1,13 @@
package buildcraft.api.gates;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.vertex.VertexFormat;
public interface IExpansionBaker<K extends GateExpansionModelKey<K>> {
/** @return The vertex format used to generate the quads. */
VertexFormat getVertexFormat();
ImmutableList<BakedQuad> bake(K key);
}
@@ -4,12 +4,9 @@
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
package buildcraft.api.gates;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -26,9 +23,5 @@ public interface IGateExpansion {
void textureStitch(TextureMap map);
@SideOnly(Side.CLIENT)
IGateStaticRenderState getRenderState();
public interface IGateStaticRenderState {
List<BakedQuad> bake(VertexFormat format);
}
GateExpansionModelKey<?> getRenderModelKey(EnumWorldBlockLayer layer);
}
@@ -22,7 +22,7 @@ public class BuildCraftExtendedProperty<T extends Comparable<T>> extends BuildCr
}
public static BuildCraftExtendedProperty<Double> create(String name, final double min, final double max) {
return new BuildCraftExtendedProperty<>(name, Double.class, new Predicate<Double>() {
return new BuildCraftExtendedProperty<Double>(name, Double.class, new Predicate<Double>() {
@Override
public boolean apply(Double input) {
return input >= min && input <= max;
@@ -1,31 +1,23 @@
package buildcraft.api.recipes;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.base.Predicate;
import net.minecraftforge.fluids.FluidStack;
public interface IComplexRefineryRecipeManager {
IHeatableRecipe createHeatingRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks);
default IHeatableRecipe addHeatableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) {
return getHeatableRegistry().addRecipe(createHeatingRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting);
}
IHeatableRecipe addHeatableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting);
ICoolableRecipe createCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks);
default ICoolableRecipe addCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) {
return getCoolableRegistry().addRecipe(createCoolableRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting);
}
ICoolableRecipe addCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting);
IDistilationRecipe createDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks);
default IDistilationRecipe addDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks, boolean replaceExisting) {
return getDistilationRegistry().addRecipe(createDistilationRecipe(in, outGas, outLiquid, ticks), replaceExisting);
}
IDistilationRecipe addDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks, boolean replaceExisting);
IComplexRefineryRegistry<IHeatableRecipe> getHeatableRegistry();
@@ -36,20 +28,12 @@ public interface IComplexRefineryRecipeManager {
public interface IComplexRefineryRegistry<R extends IComplexRefineryRecipe> {
/** @return an unmodifiable set containing all of the distilation recipies that satisfy the given predicate. All
* of the recipe objects are guarenteed to never be null. */
Stream<R> getRecipes(Predicate<R> toReturn);
default Set<R> getRecipesAsSet(Predicate<R> toReturn) {
return getRecipes(toReturn).collect(Collectors.toCollection(() -> new HashSet<>()));
}
Set<R> getRecipes(Predicate<R> toReturn);
/** @return an unmodifiable set containing all of the distilation recipies. */
default Set<R> getAllRecipes() {
return getRecipesAsSet(r -> true);
}
Set<R> getAllRecipes();
default R getRecipeForInput(FluidStack fluid) {
return getRecipes(r -> r.in().equals(fluid)).findAny().orElse(null);
}
R getRecipeForInput(FluidStack fluid);
Set<R> removeRecipes(Predicate<R> toRemove);
@@ -8,8 +8,8 @@ public interface IActionInternal extends IStatement {
void actionActivate(IStatementContainer source, IStatementParameter[] parameters);
/** @return True if this action should only be fired for the first tick of it being active. */
default boolean singleActionTick() {
return false;
public interface IActionInternalSingle extends IActionInternal {
/** @return True if this action should only be fired for the first tick of it being active. */
boolean singleActionTick();
}
}
@@ -145,6 +145,10 @@ public final class StatementManager {
}
private static IStatementParameter createParameter(Class<? extends IStatementParameter> param) {
if (param == null) {
return null;
}
try {
return param.newInstance();
} catch (InstantiationException e) {
@@ -6,6 +6,7 @@ package buildcraft.api.transport;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
@@ -23,6 +24,8 @@ public interface IPipeTile extends IInjectable {
World getWorldBC();
BlockPos getPosBC();
/** True if the pipe is connected to the block/pipe in the specific direction
*
* @param with
@@ -2,7 +2,7 @@
*
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
@API(apiVersion = "4.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport")
@API(apiVersion = "5.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport")
package buildcraft.api.transport;
import net.minecraftforge.fml.common.API;
@@ -24,15 +24,6 @@ public interface IInsertionManager {
boolean tryInsertFluid(IPipeContentsEditableFluid fluid, Object extractor, EnumFacing direction, boolean simulate);
default boolean tryInsert(IPipeContentsEditable contents, Object extractor, EnumFacing direction, boolean simulate) {
if (contents instanceof IPipeContentsEditableItem) {
return tryInsertItems((IPipeContentsEditableItem) contents, extractor, direction, simulate);
} else if (contents instanceof IPipeContentsEditableFluid) {
return tryInsertFluid((IPipeContentsEditableFluid) contents, extractor, direction, simulate);
}
return false;
}
/** @return True if {@link #tryExtractItems(IStackFilter, Object, EnumFacing, boolean)} can return a non-null
* value at any future point in time. */
boolean acceptsItems();
@@ -39,16 +39,12 @@ public interface IPipe_BC8 extends INBTLoadable_BC8<IPipe_BC8> {
/** Makes this pipe send a client update at some point in the future. This might send it now, or it might send it
* next tick. */
default void scheduleClientUpdate(IPipeListener listener) {
sendClientUpdate(listener);
}
void scheduleClientUpdate(IPipeListener listener);
/** Makes this pipe re-render its static parts. */
void sendRenderUpdate();
/** Makes this pipe send a render update at some point in the future. This might send it now, or it might send it in
* a few ticks time. */
default void scheduleRenderUpdate() {
sendRenderUpdate();
}
void scheduleRenderUpdate();
}
@@ -2,8 +2,12 @@ package buildcraft.api.transport.pluggable;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import buildcraft.api.transport.IPipe;
@SideOnly(Side.CLIENT)
public interface IPipePluggableDynamicRenderer {
void renderDynamicPluggable(IPipe pipe, EnumFacing side, PipePluggable pipePluggable, double x, double y, double z);
}
@@ -1,19 +0,0 @@
package buildcraft.api.transport.pluggable;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.util.EnumFacing;
import buildcraft.api.transport.IPipe;
public interface IPipePluggableStaticRenderer {
List<BakedQuad> bakeCutout(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable, EnumFacing face);
/** Use this if you need to render in the translucent pass. */
public interface Translucent extends IPipePluggableStaticRenderer {
/** For performance return a list that is as small as possible */
List<BakedQuad> bakeTranslucent(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable,
EnumFacing face);
}
}
@@ -0,0 +1,17 @@
package buildcraft.api.transport.pluggable;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IPluggableModelBaker<K extends PluggableModelKey<K>> {
/** @return The vertex format used to generate the quads. */
VertexFormat getVertexFormat();
ImmutableList<BakedQuad> bake(K key);
}
@@ -7,6 +7,8 @@ package buildcraft.api.transport.pluggable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -46,14 +48,14 @@ public abstract class PipePluggable implements INBTStoreable, ISerializable {
public abstract AxisAlignedBB getBoundingBox(EnumFacing side);
@SideOnly(Side.CLIENT)
public abstract IPipePluggableStaticRenderer getRenderer();
@SideOnly(Side.CLIENT)
public IPipePluggableDynamicRenderer getDynamicRenderer() {
return null;
}
@SideOnly(Side.CLIENT)
public abstract PluggableModelKey<?> getModelRenderKey(EnumWorldBlockLayer layer, EnumFacing side);
public boolean requiresRenderUpdate(PipePluggable old) {
return true;
}
@@ -0,0 +1,45 @@
package buildcraft.api.transport.pluggable;
import java.util.Arrays;
import java.util.Objects;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class PluggableModelKey<K extends PluggableModelKey<K>> {
public final EnumWorldBlockLayer layer;
public final IPluggableModelBaker<K> baker;
public final EnumFacing side;
private final int hash;
public PluggableModelKey(EnumWorldBlockLayer layer, IPluggableModelBaker<K> baker, EnumFacing side) {
this.layer = layer;
if (layer != EnumWorldBlockLayer.CUTOUT && layer != EnumWorldBlockLayer.TRANSLUCENT) {
throw new IllegalArgumentException("Can only use CUTOUT or TRANSLUCENT at the moment (was " + layer + ")");
}
if (baker == null) throw new NullPointerException("baker");
this.baker = baker;
this.side = side;
/* Don't inclue the block layer in the hash code as there are different caches for cutout and translucent */
this.hash = Arrays.hashCode(new int[] { System.identityHashCode(baker), Objects.hashCode(side) });
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
PluggableModelKey<?> other = (PluggableModelKey<?>) obj;
if (baker != other.baker) return false;
if (side != other.side) return false;
return true;
}
@Override
public int hashCode() {
return hash;
}
}