Skip to content

Commit

Permalink
Fix/crashes expceptions (#954)
Browse files Browse the repository at this point in the history
* merge guard improvements

* add that but have to remove imports

* Fix merge problems.

* merge builder changes

* Fix merge conflicts

* fix some things in placement handler, have to wait for 1.11 capabilities

* fix recipe handler

* merge saturation

* Hotfix/fix happiness (#905)

* save happiness and don't devidi through 0

* add constants

* check if citizenData != null first

* fix assets

* another hotfix, new citizen cause crash if happiness 1

* don't double request resources

* Fix prboblem with incorrect amount of entities requesting

* Fix crash with full inventory on food pickup

* fi xnullpointer

* delay warehouse more

* remove unnecessary import

* fix merge issues

* optimize imports

* merge hotfix

* fix crashes and exceptions

* correct predicate chaining and fix flintNSteel

* Fix bug where things don't get dumped correctly

* Update InventoryUtils.java

* make marvin happy

* fix citizenData null crash

* fix name

* improve creative tab

* Fix up nullpointer exception

* merge builder and lj positioning

* merge sonar fix

* fix merge bugs

* change creativetab
  • Loading branch information
Raycoms committed May 9, 2017
1 parent f5d758c commit 54807c1
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 300 deletions.
17 changes: 12 additions & 5 deletions src/main/java/com/minecolonies/coremod/colony/CitizenData.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,25 @@ public void initializeFromEntity(@NotNull final EntityCitizen entity)
*/
private String generateName(@NotNull final Random rand)
{
final String firstName;
if (!female)
String citizenName;
if (female)
{
firstName = String.format("%s %s. %s", getRandomElement(rand, Configurations.femaleFirstNames), getRandomLetter(rand),
citizenName = String.format("%s %s. %s", getRandomElement(rand, Configurations.femaleFirstNames), getRandomLetter(rand),
getRandomElement(rand, Configurations.lastNames));
}
else
{
firstName = String.format("%s %s. %s", getRandomElement(rand, Configurations.maleFirstNames), getRandomLetter(rand),
citizenName = String.format("%s %s. %s", getRandomElement(rand, Configurations.maleFirstNames), getRandomLetter(rand),
getRandomElement(rand, Configurations.lastNames));
}
return String.format("%s %s. %s", firstName, getRandomLetter(rand), getRandomElement(rand, Configurations.lastNames));
for (int i = 1; i <= this.getColony().getMaxCitizens(); i++)
{
if (this.getColony().getCitizen(i) != null && this.getColony().getCitizen(i).getName().equals(citizenName))
{
citizenName = generateName(rand);
}
}
return citizenName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class ModCreativeTabs
@Override
public ItemStack getTabIconItem()
{
this.setBackgroundImageName("minecolonies_background.jpg");
this.setBackgroundImageName("minecolonies_background.png");
this.setNoScrollbar();
return new ItemStack(ModBlocks.blockHutTownHall);
}
Expand Down
65 changes: 33 additions & 32 deletions src/main/java/com/minecolonies/coremod/entity/EntityCitizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,47 +606,48 @@ public void addExperience(final double xp)
return;
}

final double maxValue = Integer.MAX_VALUE - citizenData.getExperience();
double localXp = xp * skillModifier / EXP_DIVIDER;
final double workBuildingLevel = getWorkBuilding() == null ? 0 : getWorkBuilding().getBuildingLevel();
final double bonusXp = workBuildingLevel * (1 + citizenHutLevel) / Math.log(this.getExperienceLevel() + 2.0D);
localXp = localXp * bonusXp;
final double saturation = citizenData.getSaturation();

if (saturation < AVERAGE_SATURATION)
if (citizenData != null)
{
if (saturation <= 0)
{
return;
}
final double maxValue = Integer.MAX_VALUE - citizenData.getExperience();
double localXp = xp * skillModifier / EXP_DIVIDER;
final double workBuildingLevel = getWorkBuilding() == null ? 0 : getWorkBuilding().getBuildingLevel();
final double bonusXp = workBuildingLevel * (1 + citizenHutLevel) / Math.log(this.getExperienceLevel() + 2.0D);
localXp = localXp * bonusXp;
final double saturation = citizenData.getSaturation();

if (saturation < LOW_SATURATION)
{
localXp -= localXp * BIG_SATURATION_FACTOR * saturation;
}
else
if (saturation < AVERAGE_SATURATION)
{
localXp -= localXp * LOW_SATURATION_FACTOR * saturation;
if (saturation <= 0)
{
return;
}

if (saturation < LOW_SATURATION)
{
localXp -= localXp * BIG_SATURATION_FACTOR * saturation;
}
else
{
localXp -= localXp * LOW_SATURATION_FACTOR * saturation;
}
}
}
else if (saturation > AVERAGE_SATURATION)
{
if (saturation > HIGH_SATURATION)
else if (saturation > AVERAGE_SATURATION)
{
localXp += localXp * BIG_SATURATION_FACTOR * saturation;
if (saturation > HIGH_SATURATION)
{
localXp += localXp * BIG_SATURATION_FACTOR * saturation;
}
else
{
localXp += localXp * LOW_SATURATION_FACTOR * saturation;
}
}
else

if (localXp > maxValue)
{
localXp += localXp * LOW_SATURATION_FACTOR * saturation;
localXp = maxValue;
}
}

if (localXp > maxValue)
{
localXp = maxValue;
}
if(citizenData != null)
{
citizenData.addExperience(localXp);

while (ExperienceUtils.getXPNeededForNextLevel(citizenData.getLevel()) < citizenData.getExperience())
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/com/minecolonies/coremod/entity/EntityFishHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ public void onUpdate()
this.setDead();
}
bounceFromGround();
if (this.inGround)
{
return;
}

moveSomeStuff();
}

Expand Down Expand Up @@ -317,10 +322,8 @@ public boolean fishHookIsOverTimeToLive()
* Update some movement things for the hook.
* Detect if the hook is on ground and maybe bounce.
* Also count how long the hook is laying on the ground or in water.
*
* @return true if the hook is killed.
*/
private boolean bounceFromGround()
private void bounceFromGround()
{
if (this.shake > 0)
{
Expand All @@ -329,15 +332,13 @@ private boolean bounceFromGround()

if (!this.inGround)
{
return false;
return;
}

this.inGround = false;
this.motionX *= (this.rand.nextDouble() * BOUNCE_MOVEMENT_LIMITER);
this.motionY *= (this.rand.nextDouble() * BOUNCE_MOVEMENT_LIMITER);
this.motionZ *= (this.rand.nextDouble() * BOUNCE_MOVEMENT_LIMITER);

return false;
}

/**
Expand Down Expand Up @@ -660,7 +661,6 @@ public int getDamage(@NotNull final EntityCitizen citizen)
* Spawns a random loot from the loot table.
* and some exp orbs.
* Should be called when retrieving a hook.
* todo: Perhaps streamline this and directly add the items?
*
* @param citizen the fisherman getting the loot.
*/
Expand Down Expand Up @@ -726,13 +726,9 @@ private ItemStack getFishingLoot(final EntityCitizen citizen)
private ItemStack getLootForLootTable(ResourceLocation lootTable)
{
final LootContext.Builder lootContextBuilder = new LootContext.Builder((WorldServer) this.world);
for (final ItemStack itemstack : this.world.getLootTableManager()
.getLootTableFromLocation(lootTable)
.generateLootForPools(this.rand, lootContextBuilder.build()))
{
return itemstack;
}
return null;
return this.world.getLootTableManager()
.getLootTableFromLocation(lootTable)
.generateLootForPools(this.rand, lootContextBuilder.build()).stream().findFirst().orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ public Entity getEntityFromEntityInfoOrNull(Template.EntityInfo entityInfo)
*/
public void resetCurrentStructure()
{
workFrom = null;
currentStructure = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure;
import com.minecolonies.coremod.entity.ai.util.AIState;
import com.minecolonies.coremod.entity.ai.util.AITarget;
import com.minecolonies.coremod.util.BlockPosUtil;
import com.minecolonies.coremod.util.BlockUtils;
import com.minecolonies.coremod.util.LanguageHandler;
import com.minecolonies.coremod.util.Log;
import com.minecolonies.coremod.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBed;
import net.minecraft.block.BlockDoor;
Expand Down Expand Up @@ -533,6 +530,39 @@ protected boolean isAlreadyCleared()
return job.getWorkOrder() != null && job.getWorkOrder().isCleared();
}

/**
* Calculates the working position.
* <p>
* Takes a min distance from width and length.
* <p>
* Then finds the floor level at that distance and then check if it does contain two air levels.
*
* @param targetPosition the position to work at.
* @return BlockPos position to work from.
*/
@Override
public BlockPos getWorkingPosition(final BlockPos targetPosition)
{
StructureWrapper wrapper = job.getStructure();
final int x1 = wrapper.getPosition().getX() - wrapper.getOffset().getX() - 1;
final int z1 = wrapper.getPosition().getZ() - wrapper.getOffset().getZ() - 1;
final int x3 = wrapper.getPosition().getX() + (wrapper.getWidth() - wrapper.getOffset().getX());
final int z3 = wrapper.getPosition().getZ() + (wrapper.getLength() - wrapper.getOffset().getZ());

final BlockPos[] edges = new BlockPos[]{new BlockPos(x1, 70, z1), new BlockPos(x3, 70, z1), new BlockPos(x1, 70, z3), new BlockPos(x3, 70, z3)};

for(final BlockPos pos: edges)
{
final BlockPos basePos = BlockPosUtil.getFloor(pos, world);
if (EntityUtils.checkForFreeSpace(world, basePos)
&& world.getBlockState(basePos.up()).getBlock() != Blocks.SAPLING)
{
return basePos;
}
}
return targetPosition;
}

/**
* Calculates after how many actions the ai should dump it's inventory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private AIState chopTree()

//take first log from queue
final BlockPos log = job.tree.peekNextLog();
if (!mineBlock(log))
if (!mineBlock(log, workFrom))
{
return getState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public Object handle(
{
if (blockState.getBlock() instanceof BlockAir)
{
placer.getWorker().setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);
placer.getWorker().setItemStackToSlot(EntityEquipmentSlot.MAINHAND, InventoryUtils.EMPTY);

placer.handleBuildingOverBlock(pos);
world.setBlockToAir(pos);
Expand Down
26 changes: 0 additions & 26 deletions src/main/resources/assets/minecolonies/gui/windowCitizen.xml

This file was deleted.

Loading

0 comments on commit 54807c1

Please sign in to comment.