Pushed current code for Runemoro to review

This commit is contained in:
Waterpicker 2019-07-19 00:26:43 -05:00
parent bfd2a5a0ae
commit 2118ba3cc3
3 changed files with 98 additions and 7 deletions

View file

@ -1,5 +1,14 @@
package org.dimdev.dimdoors.shared.rifts.targets;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemDye;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.oredict.DyeUtils;
import net.minecraftforge.oredict.OreDictionary;
import org.dimdev.ddutils.RGBA;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.pocketlib.PrivatePocketData;
@ -16,6 +25,7 @@ import lombok.ToString;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import java.util.Optional;
import java.util.UUID;
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
@ -35,8 +45,7 @@ public class PrivatePocketTarget extends VirtualTarget implements IEntityTarget
// set to where the pocket was first created
pocket = PocketGenerator.generatePrivatePocket(virtualLocation != null ? virtualLocation.toBuilder().depth(-1).build() : null);
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
((IEntityTarget) RiftRegistry.instance().getPocketEntrance(pocket).getTileEntity()).receiveEntity(entity, relativeYaw, relativePitch);
RiftRegistry.instance().setLastPrivatePocketExit(uuid, location);
processEntity(pocket, RiftRegistry.instance().getPocketEntrance(pocket).getTileEntity(), entity, uuid, relativeYaw, relativePitch);
return true;
} else {
Location destLoc = RiftRegistry.instance().getPrivatePocketEntrance(uuid); // get the last used entrances
@ -47,8 +56,9 @@ public class PrivatePocketTarget extends VirtualTarget implements IEntityTarget
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
destLoc = RiftRegistry.instance().getPocketEntrance(pocket);
}
((IEntityTarget) destLoc.getTileEntity()).receiveEntity(entity, relativeYaw, relativePitch);
RiftRegistry.instance().setLastPrivatePocketExit(uuid, location);
System.out.println("Herp");
processEntity(pocket, destLoc.getTileEntity(), entity, uuid, relativePitch, relativePitch);
return true;
}
} else {
@ -56,6 +66,23 @@ public class PrivatePocketTarget extends VirtualTarget implements IEntityTarget
}
}
private void processEntity(Pocket pocket, TileEntity tileEntity, Entity entity, UUID uuid, float relativeYaw, float relativePitch) {
if(entity instanceof EntityItem) {
Optional<EnumDyeColor> dye = DyeUtils.colorFromStack(((EntityItem) entity).getItem());
System.out.println(((EntityItem) entity).getItem().getItem().getRegistryName());
if(dye.isPresent() && pocket.addDye(entity.world.getPlayerEntityByName(((EntityItem) entity).getThrower()), dye.get())) {
entity.setDead();
} else {
((IEntityTarget) tileEntity).receiveEntity(entity, relativeYaw, relativePitch);
}
} else {
((IEntityTarget) tileEntity).receiveEntity(entity, relativeYaw, relativePitch);
RiftRegistry.instance().setLastPrivatePocketExit(uuid, location);
}
}
@Override
public RGBA getColor() {
return new RGBA(0, 1, 0, 1);

View file

@ -2,21 +2,30 @@ package org.dimdev.pocketlib;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.dimdev.annotatednbt.NBTSerializable;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.ddutils.WorldUtils;
import org.dimdev.ddutils.nbt.INBTStorable;
import org.dimdev.ddutils.nbt.NBTUtils;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
import java.util.Arrays;
import java.util.Collections;
@NBTSerializable public class Pocket implements INBTStorable {
@Saved @Getter protected int id;
@Saved @Getter protected int x; // Grid x TODO: convert to non-grid dependant coordinates
@Saved @Getter protected int z; // Grid y
@Saved @Getter @Setter protected int size; // TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc.
@Saved @Getter @Setter protected VirtualLocation virtualLocation;
@Saved protected EnumDyeColor dyedColor = EnumDyeColor.WHITE;
@Saved protected EnumDyeColor color;
@Saved protected int count = 0;
@ -49,12 +58,64 @@ import org.dimdev.ddutils.nbt.NBTUtils;
return new BlockPos(x * gridSize * 16, 0, z * gridSize * 16);
}
public void addDye(EnumDyeColor color) {
public boolean addDye(Entity entity, EnumDyeColor color) {
int maxDye = amountOfDyeRequiredToColor(this);
if(this.dyedColor == color) {
DimDoors.sendTranslatedMessage(entity, "dimdoors.pockets.dyeAlreadyAbsorbed");
return false;
}
if(this.color != null && this.color == color) {
count++;
if(count+1 > amountOfDyeRequiredToColor(this)) {
dyedColor = color;
this.color = null;
this.count = 0;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.pocketHasBeenDyed", dyedColor);
return true;
} else {
count++;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color);
return true;
}
} else {
this.color = color;
count = 1;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color);
return true;
}
}
/*private void repaint(EnumDyeColor dyeColor) {
short size = (short) ((this.size + 1) * 16 - 1);
BlockPos origin = getOrigin();
World world = WorldUtils.getWorld(dim);
IBlockState innerWall = ModBlocks.FABRIC.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property
IBlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor);
for (int x = origin.getX(); x < origin.getX() + size; x++) {
for (int y = origin.getY(); y < origin.getY() + size; y++) {
for (int z = origin.getZ(); z < origin.getZ() + size; z++) {
int layer = Collections.min(Arrays.asList(x, y, z, size - 1 - x, size - 1 - y, size - 1 - z));
if (layer == 0) {
if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) {
world.setBlockState(x, y, z, outerWall);
}
} else if (layer < 5) {
if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) {
world.setBlockState(x, y, z, innerWall);
}
}
}
}
}
return schematic;
}*/
private static int amountOfDyeRequiredToColor(Pocket pocket) {
int s = 16 * pocket.getSize();
return (int) ((Math.pow(s, 3) - Math.pow(s - 10, 3))/1106);
}
}

View file

@ -162,6 +162,9 @@ dimdoors.pockets.loadAllSchematics=Load All Schematics
dimdoors.pockets.loadAllSchematics.tooltip= When true, all available Pocket Schematics will be loaded on game-start, even if the gridSize and pocketSize configuration fields would exclude these schematics from being used in 'naturally generated' pockets. The /pocket command can be used to force-generate these pockets for dungeon building or testing purposes.
dimdoors.pockets.cachedSchematics=Maximum number of cached schematics
dimdoors.pockets.cachedSchematics.tooltip= The maximum number of schematics cached as NBT instead of bytes. If a schematic is cached, it will be faster to place, but takes up more RAM. Schematics that are used more are more likely to be cached. The cache resets on restart.
dimdoors.pockets.dyeAlreadyAbsorbed=The pocket is already that color, so the rift didn't absorb the dye.
dimdoors.pocket.pocketHasBeenDyed=The pocket has been dyed %s.
dimdoors.pocket.remainingNeededDyes=The pocket has %s/%s of the dyes needed to be colored %s.
dimdoors.world=World Generation Settings
dimdoors.world.tooltip=Settings that determine where dimensional gateways and rift clusters can be generated and at what frequency