Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Small tweaks #284

Open
wants to merge 11 commits into
base: minecraft-1.12
Choose a base branch
from
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ minecraft {
replace '${mc_version}', project.mc_version
replace '${cct_version}', project.cct_version
replace '${forge_version}', project.forge_version

}

jar {
Expand Down Expand Up @@ -129,7 +130,7 @@ dependencies {
// compileOnly "org.squiddev:forgelint:0.1.1"
compileOnly "com.google.errorprone:error_prone_annotations:2.0.21"

testCompile 'junit:junit:4.11'
testImplementation 'junit:junit:4.11'
}

processResources {
Expand Down Expand Up @@ -174,7 +175,7 @@ curseforge {
changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/plethora/releases/tag/v${project.version})."

relations {
requiredLibrary 'cc-tweaked'
requiredDependency 'cc-tweaked'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Mod properties
mod_version=1.2.3
mod_version=1.2.4
cct_version=1.86.2

# Minecraft properties (update mods.toml when changing)
mc_version=1.12.2
forge_version=14.23.5.2768
mappings_version=20200429-1.15.1
mappings_version=20200429-1.15.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface ICostHandler {
*/
double get();

double getLimit();

/**
* Consume a set amount of energy
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import dan200.computercraft.api.lua.LuaException;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.squiddev.plethora.api.Injects;
import org.squiddev.plethora.utils.NBTUtilsRecursive;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -93,6 +97,14 @@ public String name() {
}
};

public static final ArgumentType<NBTTagCompound> NBT_TAG_COMPOUND_ARG = TABLE.map(NBTUtilsRecursive::encodeNBTTagCompound);

public static final ArgumentType<EntityEntry> ENTITY_ARG = RESOURCE.map(name -> {
EntityEntry entityEntry = ForgeRegistries.ENTITIES.getValue(name);
if (entityEntry == null || !ForgeRegistries.ENTITIES.containsKey(name)) throw new LuaException("Unknown entity '" + name + "'");
return entityEntry;
});

private ArgumentTypes() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public synchronized double get() {
return value;
}

@Override
public double getLimit() {
return CostSystem.limit;
}

@Override
public synchronized boolean consume(double amount) {
if (amount < 0) throw new IllegalArgumentException("amount must be >= 0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ public double get() {
return 0;
}

@Override
public double getLimit() {
return 0;
}

@Override
public boolean consume(double amount) {
if (amount < 0) throw new IllegalArgumentException("amount must be >= 0");
return amount == 0;
}

@Override
public MethodResult await(double amount, MethodResult next) throws LuaException {
throw new LuaException("Insufficient energy (requires " + amount + ", has 0).");
}

@Override
public MethodResult await(double amount, Callable<MethodResult> next) throws LuaException {
throw new LuaException("Insufficient energy (requires " + amount + ", has 0).");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ private static boolean loadLuaArg(MethodVisitor mw, int index, Parameter paramet
}
} else if (argument == double.class) {
if (def == null) {
visitGet(mw, "Real", "D");
visitGet(mw, "Double", "D");
} else {
loadDouble(mw, def.defDoub());
visitOpt(mw, "Real", "D");
visitOpt(mw, "Double", "D");
}
} else if (argument == float.class) {
if (def == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public static final class Scanner {
@Range(min = 0)
public static int scanLevelCost;

/**
* The additional cost each level incurs for rayTrace().
*/
@DefaultInt(5)
@Range(min = 0)
public static int rayTraceCost;

private Scanner() {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.squiddev.plethora.api.Constants;
import org.squiddev.plethora.api.PlethoraAPI;
import org.squiddev.plethora.api.method.IContextBuilder;
Expand Down Expand Up @@ -149,7 +150,7 @@ public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player
}

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase player, int remaining) {
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, World world, @Nonnull EntityLivingBase player, int remaining) {
if (world.isRemote) return;
if (isBlacklisted(stack)) return;

Expand Down Expand Up @@ -193,7 +194,7 @@ public int getMaxItemUseDuration(ItemStack stack) {

@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack) {
public boolean hasEffect(@Nonnull ItemStack stack) {
return super.hasEffect(stack) || getLevel(stack) > 0;
}

Expand Down Expand Up @@ -229,7 +230,7 @@ public void addInformation(ItemStack stack, World world, List<String> out, ITool

@Nonnull
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound tag) {
public ICapabilityProvider initCapabilities(@Nonnull ItemStack stack, NBTTagCompound tag) {
return new ItemModuleHandler(stack);
}

Expand Down Expand Up @@ -299,7 +300,7 @@ public void getAdditionalContext(@Nonnull IModuleAccess access, @Nonnull IContex
// Inject range information for scanners
int level = getLevel(stack);
builder.addContext(moduleKey, RangeInfo.of(level,
x -> x * ConfigGameplay.Scanner.scanLevelCost,
x -> (x+1) * ConfigGameplay.Scanner.scanLevelCost,
x -> getEffectiveRange(x, ConfigGameplay.Scanner.radius, ConfigGameplay.Scanner.maxRadius)
));
break;
Expand All @@ -309,7 +310,7 @@ public void getAdditionalContext(@Nonnull IModuleAccess access, @Nonnull IContex
// Inject range information for sensors
int level = getLevel(stack);
builder.addContext(moduleKey, RangeInfo.of(level,
x -> x * ConfigGameplay.Sensor.senseLevelCost,
x -> (x+1) * ConfigGameplay.Sensor.senseLevelCost,
x -> getEffectiveRange(x, ConfigGameplay.Sensor.radius, ConfigGameplay.Sensor.maxRadius)
));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dan200.computercraft.api.lua.LuaException;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import org.squiddev.plethora.api.method.IContext;
import org.squiddev.plethora.api.method.MethodResult;
import org.squiddev.plethora.api.method.TypedLuaObject;
Expand Down Expand Up @@ -166,6 +167,7 @@ public static TypedLuaObject<Item2D> addItem(
model.setScale(scale);
model.setItem(item);
model.setDamage(damage);
model.setNBTTagCompound(new NBTTagCompound());

canvas.add(model);
return baked.makeChild(model, canvas.reference(model)).getObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.squiddev.plethora.gameplay.modules.glasses.methods;

import com.mojang.authlib.GameProfile;
import dan200.computercraft.api.lua.LuaException;
import net.minecraft.item.Item;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.registry.EntityEntry;
import org.squiddev.plethora.api.IWorldLocation;
import org.squiddev.plethora.api.method.ContextKeys;
import org.squiddev.plethora.api.method.IContext;
Expand All @@ -15,6 +17,9 @@
import org.squiddev.plethora.gameplay.modules.glasses.objects.ObjectGroup.Group3D;
import org.squiddev.plethora.gameplay.modules.glasses.objects.ObjectGroup.Origin3D;
import org.squiddev.plethora.gameplay.modules.glasses.objects.object3d.*;
import org.squiddev.plethora.integration.EntityIdentifier;

import java.util.UUID;

import static dan200.computercraft.api.lua.ArgumentHelper.optInt;
import static org.squiddev.plethora.api.method.ArgumentHelper.getFloat;
Expand Down Expand Up @@ -52,33 +57,19 @@ public static TypedLuaObject<ObjectFrame> addFrame(IContext<Group3D> baked, @Fro
}

@PlethoraMethod(worldThread = false,
doc = "function(x:number, y:number, z:number[, width:number, height:number, depth:number][, color:number]):table -- Create a new box."
doc = "function(x: table, [, width:number, height:number, depth:number][, color:number]):table -- Create a new box."
)
public static TypedLuaObject<Box> addBox(IContext<Group3D> baked, @FromContext CanvasServer canvas, Object[] args) throws LuaException {
double x = getFloat(args, 0);
double y = getFloat(args, 1);
double z = getFloat(args, 2);

int colour;
double width, height, depth;
if (args.length <= 4) {
width = 1;
height = 1;
depth = 1;
colour = optInt(args, 3, DEFAULT_COLOUR);
} else {
width = getFloat(args, 3);
height = getFloat(args, 4);
depth = getFloat(args, 5);
colour = optInt(args, 6, DEFAULT_COLOUR);
}
public static TypedLuaObject<Box> addBox(IContext<Group3D> baked, @FromContext CanvasServer canvas, Vec3d position,
@Optional(defDoub = 1) double width, @Optional(defDoub = 1) double height,
@Optional(defDoub = 1) double depth, @Optional(defInt = DEFAULT_COLOUR) int colour) {

Group3D group = baked.getTarget();

Box box = new Box(canvas.newObjectId(), group.id());
box.setPosition(new Vec3d(x, y, z));
box.setPosition(position);
box.setSize(width, height, depth);
box.setColour(colour);
box.setRotation(Vec3d.ZERO);

canvas.add(box);

Expand All @@ -89,7 +80,7 @@ public static TypedLuaObject<Box> addBox(IContext<Group3D> baked, @FromContext C
public static TypedLuaObject<Line3D> addLine(
IContext<Group3D> baked, @FromContext CanvasServer canvas,
Vec3d start, Vec3d end,
@Optional(defDoub = 1.0f) float thickness, @Optional(defInt = DEFAULT_COLOUR) int colour
@Optional(defDoub = 1.0f) float thickness, @Optional() int colour
) {
Group3D group = baked.getTarget();

Expand All @@ -104,6 +95,58 @@ public static TypedLuaObject<Line3D> addLine(
return baked.makeChild(line, canvas.reference(line)).getObject();
}



@PlethoraMethod(doc = "function(position: table, entity: string, scale: number): table-- Create a entity model.", worldThread = false)
public static TypedLuaObject<Entity3D> addEntity(IContext<Group3D> baked, @FromContext CanvasServer canvas,
Vec3d position, EntityEntry entityEntry,
@Optional(defDoub = 1) float scale) {
Group3D group = baked.getTarget();

Entity3D model = new Entity3D(canvas.newObjectId(), group.id());
model.setEntityEntry(entityEntry);
model.setPosition(position);
model.setScale(scale);

canvas.add(model);

return baked.makeChild(model, canvas.reference(model)).getObject();
}

// @PlethoraMethod(doc = "function(position: table, entity: string, scale: number): table-- Create a entity model.", worldThread = false)
// public static TypedLuaObject<Player3D> addPlayerByUUID(IContext<Group3D> baked, @FromContext CanvasServer canvas,
// Vec3d position, UUID uuid,
// @Optional(defDoub = 1) float scale) {
// Group3D group = baked.getTarget();
//
// Player3D model = new Player3D(canvas.newObjectId(), group.id());
// model.setPlayerIdentifier(new EntityIdentifier.Player(new GameProfile(uuid,null)));
// model.setPosition(position);
// model.setScale(scale);
//
// canvas.add(model);
//
// return baked.makeChild(model, canvas.reference(model)).getObject();
// }
//
// @PlethoraMethod(doc = "function(position: table, entity: string, scale: number): table-- Create a entity model.", worldThread = false)
// public static TypedLuaObject<Player3D> addPlayerByName(IContext<Group3D> baked, @FromContext CanvasServer canvas,
// Vec3d position, String name,
// @Optional(defDoub = 1) float scale) {
// Group3D group = baked.getTarget();
//
// Player3D model = new Player3D(canvas.newObjectId(), group.id());
// model.setPlayerIdentifier(new EntityIdentifier.Player(new GameProfile(null, name)));
// model.setPosition(position);
// model.setScale(scale);
//
// canvas.add(model);
//
// return baked.makeChild(model, canvas.reference(model)).getObject();
// }



@PlethoraMethod(doc = "-- Create a item model.", worldThread = false)
public static TypedLuaObject<Item3D> addItem(
IContext<ObjectGroup.Group3D> baked, @FromContext CanvasServer canvas,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.squiddev.plethora.gameplay.modules.glasses.objects;

import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.NBTTagCompound;
import org.squiddev.plethora.api.method.MethodResult;
import org.squiddev.plethora.api.method.wrapper.FromTarget;
import org.squiddev.plethora.api.method.wrapper.PlethoraMethod;

public interface NBTTaggable {

NBTTagCompound getNBTTagCompound();

void setNBTTagCompound(NBTTagCompound nbt);

@PlethoraMethod(doc = "function(): table -- Get all NBT tags for this object", worldThread = false)
static MethodResult getNBTTags(@FromTarget NBTTaggable object) {
return MethodResult.result(NBTUtil.toLua(object.getNBTTagCompound()));
}


@PlethoraMethod(doc = "function(nbt: table): nil -- Update a NBT Tag value for this object", worldThread = false)
static void setNBTTags(@FromTarget NBTTaggable object, NBTTagCompound nbt) {
object.setNBTTagCompound(nbt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public final class ObjectRegistry {
public static final byte BOX_3D = 11;
public static final byte ITEM_3D = 12;
public static final byte LINE_3D = 13;
public static final byte ENTITY = 14;

private static final BaseObject.Factory[] FACTORIES = new BaseObject.Factory[]{
private static final BaseObject.Factory[] FACTORIES = new BaseObject.Factory[]{
Rectangle::new,
Line::new,
Dot::new,
Expand All @@ -38,7 +39,8 @@ public final class ObjectRegistry {
ObjectFrame::new,
Box::new,
Item3D::new,
Line3D::new
Line3D::new,
Entity3D::new
};

private ObjectRegistry() {
Expand Down
Loading