use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.
the class TEDemonPortal method createRandomHouse.
public int createRandomHouse(int buildingTier) {
int next = rand.nextInt(4);
ForgeDirection dir;
switch(next) {
case 0:
dir = ForgeDirection.NORTH;
break;
case 1:
dir = ForgeDirection.SOUTH;
break;
case 2:
dir = ForgeDirection.EAST;
break;
case 3:
dir = ForgeDirection.WEST;
break;
default:
dir = ForgeDirection.NORTH;
}
// Second: 1 *
Int3 space = this.findRoadSpaceFromDirection(dir, (rand.nextInt(negXRadius + negZRadius + posXRadius + posZRadius)) + 1);
int x = space.xCoord;
int z = space.zCoord;
int yLevel = space.yCoord;
if (printDebug)
AlchemicalWizardry.logger.info("Road space - x: " + x + " z: " + z);
GridSpaceHolder grid = this.createGSH();
if (!this.getGridSpace(x, z).isRoadSegment()) {
return 0;
}
List<ForgeDirection> directions = new ArrayList();
for (int i = 2; i < 6; i++) {
ForgeDirection testDir = ForgeDirection.getOrientation(i);
if (this.getGridSpace(x + testDir.offsetX, z + testDir.offsetZ).isEmpty()) {
directions.add(testDir);
}
}
if (directions.isEmpty()) {
return 0;
}
HashMap<ForgeDirection, List<DemonBuilding>> schemMap = new HashMap();
for (ForgeDirection nextDir : directions) {
for (DemonBuilding build : TEDemonPortal.buildingList) {
if (build.buildingTier != buildingTier || build.buildingType != DemonBuilding.BUILDING_HOUSE) {
continue;
}
Int3 offsetSpace = build.getGridOffsetFromRoad(nextDir, yLevel);
int xOff = offsetSpace.xCoord;
int zOff = offsetSpace.zCoord;
if (build.isValid(grid, x + xOff, z + zOff, nextDir.getOpposite())) {
if (schemMap.containsKey(nextDir)) {
schemMap.get(nextDir).add(build);
} else {
schemMap.put(nextDir, new ArrayList());
schemMap.get(nextDir).add(build);
}
} else {
if (printDebug)
AlchemicalWizardry.logger.info("This ISN'T valid!");
}
}
}
if (schemMap.keySet().isEmpty()) {
return 0;
}
ForgeDirection chosenDirection = (ForgeDirection) schemMap.keySet().toArray()[new Random().nextInt(schemMap.keySet().size())];
DemonBuilding build = schemMap.get(chosenDirection).get(new Random().nextInt(schemMap.get(chosenDirection).size()));
Int3 offsetSpace = build.getGridOffsetFromRoad(chosenDirection, yLevel);
int xOff = offsetSpace.xCoord;
int zOff = offsetSpace.zCoord;
build.destroyAllInField(worldObj, xCoord + (x + xOff) * 5, yLevel, zCoord + (z + zOff) * 5, chosenDirection.getOpposite());
build.buildAll(this, worldObj, xCoord + (x + xOff) * 5, yLevel, zCoord + (z + zOff) * 5, chosenDirection.getOpposite(), true);
build.setAllGridSpaces(x + xOff, z + zOff, yLevel, chosenDirection.getOpposite(), GridSpace.HOUSE, grid);
this.loadGSH(grid);
DemonVillagePath path = new DemonVillagePath(xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection, 2);
Int3AndBool temp = path.constructFullPath(this, worldObj, this.getRoadStepClearance());
return build.getNumberOfGridSpaces();
}
use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.
the class EntityMinorDemonGrunt method isSamePortal.
@Override
public boolean isSamePortal(IHoardDemon demon) {
Int3 position = demon.getPortalLocation();
TileEntity portal = worldObj.getTileEntity(this.demonPortal.xCoord, this.demonPortal.yCoord, this.demonPortal.zCoord);
return portal instanceof TEDemonPortal ? portal == worldObj.getTileEntity(position.xCoord, position.yCoord, position.zCoord) : false;
}
use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.
the class DemonVillagePath method constructFullPath.
public Int3AndBool constructFullPath(TEDemonPortal portal, World world, int clearance) {
int xi = this.xPos;
int yi = this.yPos;
int zi = this.zPos;
int rad = this.getRoadRadius();
int value = 0;
int finalYPos = this.constructPartialPath(portal, world, clearance, xi - rad * dir.offsetX, yi, zi - rad * dir.offsetZ, dir, length + rad, false);
for (int i = -rad; i <= rad; i++) {
value = Math.max(this.constructPartialPath(portal, world, clearance, xi - rad * dir.offsetX + i * dir.offsetZ, yi, zi - rad * dir.offsetZ + i * dir.offsetX, dir, length + 2 * rad, true), value);
if (TEDemonPortal.printDebug)
System.out.println("" + (length + 2 * rad) + ", " + value + "");
}
Int3 position = new Int3(xi, finalYPos, zi);
boolean bool = value >= length + 2 * rad;
return new Int3AndBool(position, bool);
}
use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.
the class RitualEffectEllipsoid method performEffect.
@Override
public void performEffect(IMasterRitualStone ritualStone) {
String owner = ritualStone.getOwner();
int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
World world = ritualStone.getWorld();
int x = ritualStone.getXCoord();
int y = ritualStone.getYCoord();
int z = ritualStone.getZCoord();
TileEntity tile = world.getTileEntity(x, y + 1, z);
if (!(tile instanceof IInventory) || ((IInventory) tile).getSizeInventory() < 3) {
return;
}
ItemStack item1 = ((IInventory) tile).getStackInSlot(0);
ItemStack item2 = ((IInventory) tile).getStackInSlot(1);
ItemStack item3 = ((IInventory) tile).getStackInSlot(2);
int xSize = item1 == null ? 0 : item1.stackSize;
int ySize = item2 == null ? 0 : item2.stackSize;
int zSize = item3 == null ? 0 : item3.stackSize;
int cost = 5;
if (currentEssence < cost) {
EntityPlayer entityOwner = SpellHelper.getPlayerForUsername(owner);
if (entityOwner == null) {
return;
}
entityOwner.addPotionEffect(new PotionEffect(Potion.confusion.id, 80));
} else {
tile = world.getTileEntity(x, y - 1, z);
if (!(tile instanceof IInventory)) {
return;
}
ItemBlock placedBlock = null;
ItemStack stack = null;
int slot = 0;
IInventory inv = (IInventory) tile;
while (slot < inv.getSizeInventory()) {
stack = inv.getStackInSlot(slot);
if (stack == null) {
slot++;
continue;
}
if (stack.getItem() instanceof ItemBlock) {
placedBlock = (ItemBlock) stack.getItem();
break;
}
slot++;
}
if (placedBlock == null || stack == null || slot >= inv.getSizeInventory()) {
return;
}
int count = 10;
Int3 lastPos = this.getLastPosition(ritualStone.getCustomRitualTag());
int i = -xSize;
int j = -ySize;
int k = -zSize;
if (lastPos != null) {
i = Math.min(xSize, Math.max(-xSize, lastPos.xCoord));
j = Math.min(ySize, Math.max(-ySize, lastPos.yCoord));
k = Math.min(zSize, Math.max(-zSize, lastPos.zCoord));
}
boolean incrementNext = false;
while (j <= ySize) {
if (y + j < 0) {
j++;
continue;
}
while (i <= xSize) {
while (k <= zSize) {
if (Math.pow(i * (ySize - 0.50f) * (zSize - 0.50f), 2) + Math.pow(j * (xSize - 0.50f) * (zSize - 0.50f), 2) + Math.pow(k * (xSize - 0.50f) * (ySize - 0.50f), 2) <= Math.pow((xSize - 1 + 0.50f) * (ySize - 1 + 0.50f) * (zSize - 1 + 0.50f), 2)) {
k++;
continue;
}
if (Math.pow(i * (ySize + 0.50f) * (zSize + 0.50f), 2) + Math.pow(j * (xSize + 0.50f) * (zSize + 0.50f), 2) + Math.pow(k * (xSize + 0.50f) * (ySize + 0.50f), 2) >= Math.pow((xSize + 0.50f) * (ySize + 0.50f) * (zSize + 0.50f), 2)) {
k++;
continue;
}
if (incrementNext || count <= 0) {
this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
return;
}
count--;
Block block = world.getBlock(x + i, y + j, z + k);
if (!block.isAir(world, x + i, y + j, z + k)) {
k++;
continue;
} else {
// This is pulled from the ItemBlock's placing calls
int i1 = placedBlock.getMetadata(stack.getItemDamage());
int j1 = placedBlock.field_150939_a.onBlockPlaced(world, x + i, y + j, z + k, 0, 0, 0, 0, i1);
if (placedBlock.placeBlockAt(stack, null, world, x + i, y + j, z + k, 0, 0, 0, 0, j1)) {
world.playSoundEffect((double) (x + i + 0.5F), (double) (y + j + 0.5F), (double) (z + k + 0.5F), placedBlock.field_150939_a.stepSound.func_150496_b(), (placedBlock.field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F, placedBlock.field_150939_a.stepSound.getPitch() * 0.8F);
--stack.stackSize;
if (stack.stackSize <= 0) {
inv.setInventorySlotContents(slot, null);
}
this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
incrementNext = true;
SoulNetworkHandler.syphonFromNetwork(owner, cost);
}
// world.setBlock(x + i, y + j, z + k, Blocks.stone);
k++;
}
}
k = -zSize;
i++;
}
i = -xSize;
j++;
this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
return;
}
this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(-xSize, -ySize, -zSize));
}
}
use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.
the class TEReagentConduit method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
hasChanged = tag.getInteger("hasChanged");
NBTTagList tagList = tag.getTagList("destinationList", Constants.NBT.TAG_COMPOUND);
destinationList = new LinkedList();
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
destinationList.add(ColourAndCoords.readFromNBT(savedTag));
}
reagentTargetList = new HashMap();
NBTTagList reagentTagList = tag.getTagList("reagentTargetList", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < reagentTagList.tagCount(); i++) {
NBTTagCompound savedTag = reagentTagList.getCompoundTagAt(i);
Reagent reagent = ReagentRegistry.getReagentForKey(savedTag.getString("reagent"));
List<Int3> coordList = new LinkedList();
NBTTagList coordinateList = savedTag.getTagList("coordinateList", Constants.NBT.TAG_COMPOUND);
for (int j = 0; j < coordinateList.tagCount(); j++) {
coordList.add(Int3.readFromNBT(coordinateList.getCompoundTagAt(j)));
}
reagentTargetList.put(reagent, coordList);
}
reagentTankDesignationList = new HashMap();
NBTTagList tankDesignationList = tag.getTagList("tankDesignationList", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tankDesignationList.tagCount(); i++) {
NBTTagCompound savedTag = tankDesignationList.getCompoundTagAt(i);
this.reagentTankDesignationList.put(ReagentRegistry.getReagentForKey(savedTag.getString("reagent")), new Integer(savedTag.getInteger("integer")));
}
}
Aggregations