|
2 | 2 |
|
3 | 3 | import lombok.Getter; |
4 | 4 | import lombok.Setter; |
| 5 | +import net.minecraft.block.state.IBlockState; |
| 6 | +import net.minecraft.entity.Entity; |
5 | 7 | import net.minecraft.item.EnumDyeColor; |
6 | 8 | import net.minecraft.nbt.NBTTagCompound; |
7 | 9 | import net.minecraft.util.math.BlockPos; |
| 10 | +import net.minecraft.world.World; |
8 | 11 | import org.dimdev.annotatednbt.NBTSerializable; |
9 | 12 | import org.dimdev.annotatednbt.Saved; |
| 13 | +import org.dimdev.ddutils.WorldUtils; |
10 | 14 | import org.dimdev.ddutils.nbt.INBTStorable; |
11 | 15 | import org.dimdev.ddutils.nbt.NBTUtils; |
| 16 | +import org.dimdev.dimdoors.DimDoors; |
| 17 | +import org.dimdev.dimdoors.shared.blocks.ModBlocks; |
12 | 18 |
|
13 | | -@NBTSerializable public class Pocket implements INBTStorable { |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.Collections; |
14 | 21 |
|
| 22 | +@NBTSerializable public class Pocket implements INBTStorable { |
15 | 23 | @Saved @Getter protected int id; |
16 | 24 | @Saved @Getter protected int x; // Grid x TODO: convert to non-grid dependant coordinates |
17 | 25 | @Saved @Getter protected int z; // Grid y |
18 | 26 | @Saved @Getter @Setter protected int size; // TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc. |
19 | 27 | @Saved @Getter @Setter protected VirtualLocation virtualLocation; |
| 28 | + @Saved protected EnumDyeColor dyedColor = EnumDyeColor.WHITE; |
20 | 29 | @Saved protected EnumDyeColor color; |
21 | 30 | @Saved protected int count = 0; |
22 | 31 |
|
@@ -49,12 +58,64 @@ public BlockPos getOrigin() { |
49 | 58 | return new BlockPos(x * gridSize * 16, 0, z * gridSize * 16); |
50 | 59 | } |
51 | 60 |
|
52 | | - public void addDye(EnumDyeColor color) { |
| 61 | + public boolean addDye(Entity entity, EnumDyeColor color) { |
| 62 | + int maxDye = amountOfDyeRequiredToColor(this); |
| 63 | + |
| 64 | + if(this.dyedColor == color) { |
| 65 | + DimDoors.sendTranslatedMessage(entity, "dimdoors.pockets.dyeAlreadyAbsorbed"); |
| 66 | + return false; |
| 67 | + } |
| 68 | + |
53 | 69 | if(this.color != null && this.color == color) { |
54 | | - count++; |
| 70 | + if(count+1 > amountOfDyeRequiredToColor(this)) { |
| 71 | + dyedColor = color; |
| 72 | + this.color = null; |
| 73 | + this.count = 0; |
| 74 | + DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.pocketHasBeenDyed", dyedColor); |
| 75 | + return true; |
| 76 | + } else { |
| 77 | + count++; |
| 78 | + DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); |
| 79 | + return true; |
| 80 | + } |
55 | 81 | } else { |
56 | 82 | this.color = color; |
57 | 83 | count = 1; |
| 84 | + DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); |
| 85 | + return true; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /*private void repaint(EnumDyeColor dyeColor) { |
| 90 | + short size = (short) ((this.size + 1) * 16 - 1); |
| 91 | + BlockPos origin = getOrigin(); |
| 92 | + World world = WorldUtils.getWorld(dim); |
| 93 | + IBlockState innerWall = ModBlocks.FABRIC.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property |
| 94 | + IBlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor); |
| 95 | +
|
| 96 | + for (int x = origin.getX(); x < origin.getX() + size; x++) { |
| 97 | + for (int y = origin.getY(); y < origin.getY() + size; y++) { |
| 98 | + for (int z = origin.getZ(); z < origin.getZ() + size; z++) { |
| 99 | + int layer = Collections.min(Arrays.asList(x, y, z, size - 1 - x, size - 1 - y, size - 1 - z)); |
| 100 | + if (layer == 0) { |
| 101 | + if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) { |
| 102 | + world.setBlockState(x, y, z, outerWall); |
| 103 | + } |
| 104 | + } else if (layer < 5) { |
| 105 | + if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) { |
| 106 | + world.setBlockState(x, y, z, innerWall); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
58 | 111 | } |
| 112 | +
|
| 113 | + return schematic; |
| 114 | + }*/ |
| 115 | + |
| 116 | + private static int amountOfDyeRequiredToColor(Pocket pocket) { |
| 117 | + int s = 16 * pocket.getSize(); |
| 118 | + |
| 119 | + return (int) ((Math.pow(s, 3) - Math.pow(s - 10, 3))/1106); |
59 | 120 | } |
60 | 121 | } |
0 commit comments