Clean
This commit is contained in:
parent
2e181a6ae1
commit
1bc2b3f933
19 changed files with 106 additions and 120 deletions
|
@ -1,24 +1,18 @@
|
|||
package org.dimdev.dimdoors.item;
|
||||
|
||||
import org.dimdev.dimdoors.sound.ModSoundEvents;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.sound.ModSoundEvents;
|
||||
|
||||
public class DimensionalEraserItem extends Item {
|
||||
public DimensionalEraserItem(Settings settings) {
|
||||
super(settings);
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileUtil;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
|
@ -15,7 +14,6 @@ import net.minecraft.util.hit.HitResult;
|
|||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
|
||||
public final class RaycastHelper {
|
||||
public static final int REACH_DISTANCE = 5;
|
||||
|
|
|
@ -21,7 +21,6 @@ import net.minecraft.util.hit.BlockHitResult;
|
|||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RiftBladeItem extends SwordItem {
|
||||
|
@ -45,13 +44,13 @@ public class RiftBladeItem extends SwordItem {
|
|||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
HitResult hit = RaycastHelper.raycast(player,16,0.0F, LivingEntity.class::isInstance);
|
||||
HitResult hit = RaycastHelper.raycast(player, 16, 0.0F, LivingEntity.class::isInstance);
|
||||
|
||||
if(hit == null) {
|
||||
if (hit == null) {
|
||||
hit = RaycastHelper.raycast(player, 16, 1.0F, LivingEntity.class::isInstance);
|
||||
}
|
||||
|
||||
if(hit == null) {
|
||||
if (hit == null) {
|
||||
hit = player.raycast(16, 1.0F, false); //TODO: make the range of the Rift Blade configurable
|
||||
}
|
||||
|
||||
|
|
|
@ -3,42 +3,42 @@ package org.dimdev.dimdoors.item;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import org.dimdev.dimdoors.network.c2s.HitBlockS2CPacket;
|
||||
import org.dimdev.dimdoors.network.s2c.PlayerInventorySlotUpdateS2CPacket;
|
||||
import org.dimdev.dimdoors.rift.targets.IdMarker;
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.world.level.Counter;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
|
||||
import static net.fabricmc.api.EnvType.CLIENT;
|
||||
|
||||
public class RiftConfigurationToolItem extends Item {
|
||||
|
@ -67,7 +67,7 @@ public class RiftConfigurationToolItem extends Item {
|
|||
EntityUtils.chat(player, Text.of("Id: " + ((IdMarker) rift.getDestination()).getId()));
|
||||
} else {
|
||||
int id = counter.increment();
|
||||
sync(stack, player, hand);
|
||||
this.sync(stack, player, hand);
|
||||
EntityUtils.chat(player, Text.of("Rift stripped of data and set to target id: " + id));
|
||||
|
||||
rift.setDestination(new IdMarker(id));
|
||||
|
@ -84,7 +84,7 @@ public class RiftConfigurationToolItem extends Item {
|
|||
|
||||
public static ActionResult onAttackBlockCallback(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||
if (world.isClient && player.isSneaking() && player.getStackInHand(hand).getItem() instanceof RiftConfigurationToolItem) {
|
||||
if(Counter.get(player.getStackInHand(hand)).count() != -1 || world.getBlockEntity(pos) instanceof RiftBlockEntity) {
|
||||
if (Counter.get(player.getStackInHand(hand)).count() != -1 || world.getBlockEntity(pos) instanceof RiftBlockEntity) {
|
||||
HitBlockS2CPacket packet = new HitBlockS2CPacket(hand, pos, direction);
|
||||
try {
|
||||
PacketByteBuf buf = PacketByteBufs.create();
|
||||
|
@ -120,7 +120,7 @@ public class RiftConfigurationToolItem extends Item {
|
|||
rift.setDestination(new IdMarker(-1));
|
||||
EntityUtils.chat(player, Text.of("Rift stripped of data and set to invalid id: -1"));
|
||||
}
|
||||
} else if (Counter.get(stack).count() != -1){
|
||||
} else if (Counter.get(stack).count() != -1) {
|
||||
Counter.get(stack).set(-1);
|
||||
((RiftConfigurationToolItem) stack.getItem()).sync(stack, player, hand);
|
||||
|
||||
|
|
|
@ -7,15 +7,12 @@ import java.util.Objects;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.cottonmc.cotton.gui.widget.WBox;
|
||||
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||
import io.github.cottonmc.cotton.gui.widget.WToggleButton;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import io.github.cottonmc.cotton.gui.widget.data.Axis;
|
||||
import org.dimdev.dimdoors.util.Codecs;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.Text;
|
||||
|
|
|
@ -5,8 +5,8 @@ import java.util.UUID;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class Rift extends RegistryVertex {
|
|||
tag.putUuid("id", rift.id);
|
||||
tag.put("location", Location.toTag(rift.location));
|
||||
tag.putBoolean("isDetached", rift.isDetached);
|
||||
if(rift.properties != null) tag.put("properties", LinkProperties.toTag(rift.properties));
|
||||
if (rift.properties != null) tag.put("properties", LinkProperties.toTag(rift.properties));
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class Rift extends RegistryVertex {
|
|||
rift.id = tag.getUuid("id");
|
||||
rift.location = Location.fromTag(tag.getCompound("location"));
|
||||
rift.isDetached = tag.getBoolean("isDetached");
|
||||
if(tag.contains("properties")) rift.properties = LinkProperties.fromTag(tag.getCompound("properties"));
|
||||
if (tag.contains("properties")) rift.properties = LinkProperties.fromTag(tag.getCompound("properties"));
|
||||
return rift;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import org.dimdev.dimdoors.util.GraphUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PocketDirectory;
|
||||
import org.dimdev.dimdoors.world.pocket.PrivateRegistry;
|
||||
import org.jgrapht.graph.DefaultDirectedGraph;
|
||||
import org.jgrapht.graph.DefaultEdge;
|
||||
|
||||
|
@ -46,7 +44,7 @@ public class RiftRegistry {
|
|||
|
||||
ListTag riftsNBT = (ListTag) nbt.get("rifts");
|
||||
for (Tag riftNBT : riftsNBT) {
|
||||
Rift rift = Rift.fromTag((CompoundTag) riftNBT);
|
||||
Rift rift = Rift.fromTag((CompoundTag) riftNBT);
|
||||
riftRegistry.graph.addVertex(rift);
|
||||
riftRegistry.uuidMap.put(rift.id, rift);
|
||||
riftRegistry.locationMap.put(rift.location, rift);
|
||||
|
@ -273,7 +271,7 @@ public class RiftRegistry {
|
|||
}
|
||||
|
||||
public Location getPocketEntrance(Pocket pocket) {
|
||||
Set<Location> entrances = this.getPocketEntrances(pocket);
|
||||
Set<Location> entrances = this.getPocketEntrances(pocket);
|
||||
return entrances.stream()
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
|
|
@ -5,10 +5,10 @@ import java.util.UUID;
|
|||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.dimdev.dimdoors.rift.targets;
|
||||
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
|
||||
public class IdMarker extends VirtualTarget implements EntityTarget {
|
||||
private final int id;
|
||||
|
||||
|
@ -30,12 +29,12 @@ public class IdMarker extends VirtualTarget implements EntityTarget {
|
|||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receiveEntity(Entity entity, float yawOffset) {
|
||||
EntityUtils.chat(entity, Text.of("This rift is configured for pocket dungeons. Its id is " + id));
|
||||
EntityUtils.chat(entity, Text.of("This rift is configured for pocket dungeons. Its id is " + this.id));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@ package org.dimdev.dimdoors.rift.targets;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.RGBA;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PocketDirectory;
|
||||
import org.dimdev.dimdoors.world.pocket.PrivateRegistry;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
|
|
@ -5,12 +5,11 @@ import java.util.UUID;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dimdev.dimdoors.pockets.PocketGenerator;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.RGBA;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PrivateRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
|
@ -66,7 +65,7 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
|
|||
Item item = ((ItemEntity) entity).getStack().getItem();
|
||||
|
||||
if (item instanceof DyeItem) {
|
||||
if(pocket.addDye(EntityUtils.getOwner(entity), ((DyeItem) item).getColor())) {
|
||||
if (pocket.addDye(EntityUtils.getOwner(entity), ((DyeItem) item).getColor())) {
|
||||
entity.remove();
|
||||
} else {
|
||||
((EntityTarget) blockEntity).receiveEntity(entity, relativeYaw);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.dimdev.dimdoors.rift.targets;
|
||||
|
||||
import org.dimdev.dimdoors.pockets.PocketGenerator;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class PublicPocketTarget extends RestoringTarget {
|
|||
public Location makeLinkTarget() {
|
||||
VirtualLocation riftVirtualLocation = VirtualLocation.fromLocation(this.location);
|
||||
VirtualLocation newVirtualLocation;
|
||||
int depth = riftVirtualLocation.getDepth()+1;
|
||||
int depth = riftVirtualLocation.getDepth() + 1;
|
||||
newVirtualLocation = new VirtualLocation(riftVirtualLocation.getWorld(), riftVirtualLocation.getX(), riftVirtualLocation.getZ(), depth);
|
||||
Pocket pocket = PocketGenerator.generatePublicPocketV2(newVirtualLocation, new GlobalReference(this.location), null);
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
|||
import org.dimdev.dimdoors.pockets.PocketGenerator;
|
||||
import org.dimdev.dimdoors.rift.registry.LinkProperties;
|
||||
import org.dimdev.dimdoors.rift.registry.Rift;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.math.MathUtil;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
|
||||
|
||||
|
@ -174,7 +174,8 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
|
|||
Pocket pocket = PocketGenerator.generateDungeonPocketV2(virtualLocation, new GlobalReference(!this.noLinkBack ? this.location : null), newLink); // TODO make the generated dungeon of the same type, but in the overworld
|
||||
|
||||
// Link the rift if necessary and teleport the entity
|
||||
if (!this.noLink) linkRifts(this.location, DimensionalRegistry.getRiftRegistry().getPocketEntrance(pocket));
|
||||
if (!this.noLink)
|
||||
linkRifts(this.location, DimensionalRegistry.getRiftRegistry().getPocketEntrance(pocket));
|
||||
return (Target) DimensionalRegistry.getRiftRegistry().getPocketEntrance(pocket).getBlockEntity();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,9 +2,9 @@ package org.dimdev.dimdoors.rift.targets;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.RGBA;
|
||||
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
|
||||
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ import java.util.Iterator;
|
|||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
package org.dimdev.dimdoors.util;
|
||||
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dimdev.dimdoors.util.math.Equation;
|
||||
|
||||
import java.util.Map;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
|
||||
public class TagEquations {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public static CompoundTag solveCompoundTagEquations(CompoundTag tag, Map<String, Double> variableMap) {
|
||||
CompoundTag solved = new CompoundTag();
|
||||
for (String key : tag.getKeys()) {
|
||||
if (tag.getType(key) == NbtType.STRING && key.startsWith("equation_")){
|
||||
if (tag.getType(key) == NbtType.STRING && key.startsWith("equation_")) {
|
||||
try {
|
||||
double solution = Equation.parse(tag.getString(key)).apply(variableMap);
|
||||
key = key.substring(9);
|
||||
if (key.startsWith("int_")) {
|
||||
key = key.substring(4);
|
||||
solved.putInt(key, (int) solution);
|
||||
}
|
||||
else if (key.startsWith("boolean_")) {
|
||||
} else if (key.startsWith("boolean_")) {
|
||||
key = key.substring(8);
|
||||
solved.putBoolean(key, Equation.toBoolean(solution));
|
||||
}
|
||||
else if (key.startsWith("double_")) {
|
||||
} else if (key.startsWith("double_")) {
|
||||
key = key.substring(7);
|
||||
solved.putDouble(key, solution);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
solved.putDouble(key, solution);
|
||||
}
|
||||
} catch (Equation.EquationParseException e) {
|
||||
|
@ -41,8 +41,7 @@ public class TagEquations {
|
|||
solved.put(key, solveCompoundTagEquations(tag.getCompound(key), variableMap));
|
||||
} else if (tag.getType(key) == NbtType.LIST) {
|
||||
solved.put(key, solveListTagEquations((ListTag) tag.get(key), variableMap));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
solved.put(key, tag.get(key));
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +50,12 @@ public class TagEquations {
|
|||
|
||||
public static ListTag solveListTagEquations(ListTag listTag, Map<String, Double> variableMap) {
|
||||
ListTag solved = new ListTag();
|
||||
for(Tag tag : listTag) {
|
||||
for (Tag tag : listTag) {
|
||||
if (tag.getType() == NbtType.LIST) {
|
||||
solved.add(solveListTagEquations((ListTag) tag, variableMap));
|
||||
}
|
||||
else if (tag.getType() == NbtType.COMPOUND) {
|
||||
} else if (tag.getType() == NbtType.COMPOUND) {
|
||||
solved.add(solveCompoundTagEquations((CompoundTag) tag, variableMap));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
solved.add(tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.world.World;
|
||||
|
|
|
@ -1,30 +1,33 @@
|
|||
package org.dimdev.dimdoors.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
public class WeightedList<T extends Weighted<P>, P> extends ArrayList<T> {
|
||||
private final Random random = new Random();
|
||||
private T peekedRandom;
|
||||
private boolean peeked = false;
|
||||
|
||||
public WeightedList() { }
|
||||
public WeightedList() {
|
||||
}
|
||||
|
||||
public WeightedList(Collection<? extends T> c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
public T getNextRandomWeighted(P parameters) {
|
||||
return getNextRandomWeighted(parameters, false);
|
||||
return this.getNextRandomWeighted(parameters, false);
|
||||
}
|
||||
|
||||
public T peekNextRandomWeighted(P parameters) {
|
||||
return getNextRandomWeighted(parameters, true);
|
||||
return this.getNextRandomWeighted(parameters, true);
|
||||
}
|
||||
|
||||
private T getNextRandomWeighted(P parameters, boolean peek) {
|
||||
if (!peeked) {
|
||||
double totalWeight = stream().mapToDouble(weighted -> weighted.getWeight(parameters)).sum();
|
||||
double cursor = random.nextDouble() * totalWeight;
|
||||
if (!this.peeked) {
|
||||
double totalWeight = this.stream().mapToDouble(weighted -> weighted.getWeight(parameters)).sum();
|
||||
double cursor = this.random.nextDouble() * totalWeight;
|
||||
if (cursor == 0) {
|
||||
for (T weighted : this) {
|
||||
if (weighted.getWeight(parameters) != 0) return weighted;
|
||||
|
@ -34,19 +37,19 @@ public class WeightedList<T extends Weighted<P>, P> extends ArrayList<T> {
|
|||
cursor -= weighted.getWeight(parameters);
|
||||
if (cursor <= 0) {
|
||||
if (peek) {
|
||||
peekedRandom = weighted;
|
||||
peeked = true;
|
||||
this.peekedRandom = weighted;
|
||||
this.peeked = true;
|
||||
}
|
||||
return weighted; // should never return an entry with weight 0, unless there are only weight 0 entries
|
||||
}
|
||||
}
|
||||
if (peek) {
|
||||
peekedRandom = null;
|
||||
peeked = true;
|
||||
this.peekedRandom = null;
|
||||
this.peeked = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!peek) peeked = false;
|
||||
return peekedRandom;
|
||||
if (!peek) this.peeked = false;
|
||||
return this.peekedRandom;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package org.dimdev.dimdoors.util.math;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface Equation {
|
||||
double FALSE = 0d;
|
||||
double TRUE = 1d;
|
||||
|
@ -13,7 +17,7 @@ public interface Equation {
|
|||
double apply(Map<String, Double> variableMap);
|
||||
|
||||
default boolean asBoolean(Map<String, Double> variableMap) {
|
||||
return toBoolean(apply(variableMap));
|
||||
return toBoolean(this.apply(variableMap));
|
||||
}
|
||||
|
||||
static Equation parse(String equationString) throws EquationParseException {
|
||||
|
@ -138,7 +142,8 @@ public interface Equation {
|
|||
public Optional<Equation> tryParse(String toParse) {
|
||||
if (!toParse.matches("[a-zA-Z_][a-zA-Z0-9_]*")) return Optional.empty();
|
||||
return Optional.of(stringDoubleMap -> {
|
||||
if (stringDoubleMap != null && stringDoubleMap.containsKey(toParse)) return stringDoubleMap.get(toParse);
|
||||
if (stringDoubleMap != null && stringDoubleMap.containsKey(toParse))
|
||||
return stringDoubleMap.get(toParse);
|
||||
LOGGER.error("Variable \"" + toParse + "\" was not passed to equation! Returning 0 as fallback.");
|
||||
return 0d;
|
||||
});
|
||||
|
@ -155,15 +160,15 @@ public interface Equation {
|
|||
@Override
|
||||
public Optional<Equation> tryParse(String toParse) throws EquationParseException {
|
||||
int depth = 0;
|
||||
for (int i = toParse.length() - 1; i >= 1 ; i--) {
|
||||
for (int i = toParse.length() - 1; i >= 1; i--) {
|
||||
String substring = toParse.substring(i);
|
||||
if (substring.startsWith(")")) depth++;
|
||||
else if (substring.startsWith("(")) depth--;
|
||||
for(String symbol : operations.keySet()) {
|
||||
for (String symbol : this.operations.keySet()) {
|
||||
if (substring.startsWith(symbol) && depth == 0) {
|
||||
final TriFunction<Map<String, Double>, Equation, Equation, Double> operation = operations.get(symbol);
|
||||
final Equation first = Equation.parse(toParse.substring(0,i));
|
||||
final Equation second = Equation.parse(toParse.substring(i+1));
|
||||
final TriFunction<Map<String, Double>, Equation, Equation, Double> operation = this.operations.get(symbol);
|
||||
final Equation first = Equation.parse(toParse.substring(0, i));
|
||||
final Equation second = Equation.parse(toParse.substring(i + 1));
|
||||
return Optional.of(stringDoubleMap -> operation.apply(stringDoubleMap, first, second));
|
||||
}
|
||||
}
|
||||
|
@ -187,19 +192,19 @@ public interface Equation {
|
|||
|
||||
@Override
|
||||
public Optional<Equation> tryParse(String toParse) throws EquationParseException {
|
||||
if (!toParse.startsWith(functionString) || !toParse.endsWith(")")) return Optional.empty();
|
||||
String[] arguments = toParse.substring(functionString.length(), toParse.length()-1).split(",");
|
||||
if (minArguments > arguments.length || (maxArguments < arguments.length && maxArguments != -1)) return Optional.empty();
|
||||
if (!toParse.startsWith(this.functionString) || !toParse.endsWith(")")) return Optional.empty();
|
||||
String[] arguments = toParse.substring(this.functionString.length(), toParse.length() - 1).split(",");
|
||||
if (this.minArguments > arguments.length || (this.maxArguments < arguments.length && this.maxArguments != -1))
|
||||
return Optional.empty();
|
||||
final Equation[] argumentEquations = new Equation[arguments.length];
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
argumentEquations[i] = Equation.parse(arguments[i]);
|
||||
}
|
||||
return Optional.of(stringDoubleMap -> function.apply(stringDoubleMap, argumentEquations));
|
||||
return Optional.of(stringDoubleMap -> this.function.apply(stringDoubleMap, argumentEquations));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private interface TriFunction<T, U, V, R> {
|
||||
R apply(T t, U u, V v);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue