Skip to content

Commit

Permalink
Update encounters sync for dedicated servers, update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodor12 committed Oct 27, 2024
1 parent 85ffe24 commit 80b4083
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@ public void registerBlockItem(final IForgeRegistry<Item> registry, final Item.Pr
registry.register(getRegistryName(), new ItemCrop(this, properties, preferredBiome));
}

/**
* Get the preferred biome for this crop.
*
* @return the preferred biome.
*/
@Nullable
public TagKey<Biome> getPreferredBiome()
{
return preferredBiome;
}

/**
* Get the preferred farmland for this crop.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.minecolonies.core.colony.expeditions.colony.types.ColonyExpeditionType;
import com.minecolonies.core.colony.expeditions.colony.types.ColonyExpeditionTypeDifficulty;
import com.minecolonies.core.colony.expeditions.encounters.ExpeditionEncounter;
import com.minecolonies.core.colony.expeditions.encounters.ExpeditionEncounterManager;
import com.minecolonies.core.datalistener.ColonyExpeditionTypeListener;
import com.minecolonies.core.datalistener.ExpeditionEncounterListener;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -283,10 +283,10 @@ public void updateElement(final int i, final Pane pane)
final MobKill item = currentStage.getKills().get(itemIndex);
final EntityIcon entityIcon = childKills.findPaneOfTypeByID(PARTIAL_ITEM_PREFIX + colIndex, EntityIcon.class);

final ExpeditionEncounter encounter = ExpeditionEncounterManager.getInstance().getEncounter(item.encounterId());
final ExpeditionEncounter encounter = ExpeditionEncounterListener.getEncounter(item.encounterId());
if (encounter != null)
{
entityIcon.setEntity(encounter.getEntityType());
entityIcon.setEntity(encounter.entityType());
entityIcon.setCount(item.count());
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.minecolonies.core.colony.expeditions.ExpeditionVisitorMember;
import com.minecolonies.core.colony.expeditions.colony.types.ColonyExpeditionType;
import com.minecolonies.core.colony.expeditions.encounters.ExpeditionEncounter;
import com.minecolonies.core.colony.expeditions.encounters.ExpeditionEncounterManager;
import com.minecolonies.core.datalistener.ColonyExpeditionTypeListener;
import com.minecolonies.core.datalistener.ExpeditionEncounterListener;
import com.minecolonies.core.entity.visitor.ExpeditionaryVisitorType.DespawnTimeData.DespawnTime;
import com.minecolonies.core.items.ItemAdventureToken;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -245,7 +245,7 @@ private void processMobFight(final @NotNull ExpeditionEncounter encounter, final
MobType mobType = MobType.UNDEFINED;
try
{
final Entity entity = encounter.getEntityType().create(colony.getWorld());
final Entity entity = encounter.entityType().create(colony.getWorld());
if (entity instanceof Mob mob)
{
mobType = mob.getMobType();
Expand All @@ -259,7 +259,7 @@ private void processMobFight(final @NotNull ExpeditionEncounter encounter, final

for (int i = 0; i < amount; i++)
{
double encounterHealth = encounter.getHealth();
double encounterHealth = encounter.health();

// Keep the fight going as long as the mob is not dead.
while (encounterHealth > 0)
Expand All @@ -273,17 +273,17 @@ private void processMobFight(final @NotNull ExpeditionEncounter encounter, final
}

final ItemStack weapon = attacker.getPrimaryWeapon();
encounterHealth -= CombatRules.getDamageAfterAbsorb(getWeaponDamage(weapon, mobType), encounter.getArmor(), 0);
encounterHealth -= CombatRules.getDamageAfterAbsorb(getWeaponDamage(weapon, mobType), encounter.armor(), 0);
if (weapon.hurt(1, random, null))
{
attacker.setPrimaryWeapon(ItemStack.EMPTY);
}

if (encounterHealth > 0)
{
final float damageAmount = handleDamageReduction(attacker, encounter.getDamage());
final float damageAmount = handleDamageReduction(attacker, encounter.damage());
attacker.setHealth(Math.max(0, attacker.getHealth() - damageAmount));
encounterHealth -= encounter.getReflectingDamage();
encounterHealth -= encounter.reflectingDamage();

if (attacker.isDead())
{
Expand All @@ -294,8 +294,8 @@ private void processMobFight(final @NotNull ExpeditionEncounter encounter, final

if (encounterHealth <= 0)
{
expedition.mobKilled(encounter.getId());
final List<ItemStack> loot = processLootTable(encounter.getLootTable(), expeditionType);
expedition.mobKilled(encounter.id());
final List<ItemStack> loot = processLootTable(encounter.lootTable(), expeditionType);
loot.forEach(this::processReward);
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private void processAdventureToken(final ItemStack itemStack)
case TOKEN_TAG_EXPEDITION_TYPE_ENCOUNTER:
{
final String encounterId = compound.getString(TOKEN_TAG_EXPEDITION_ENCOUNTER);
final ExpeditionEncounter encounter = ExpeditionEncounterManager.getInstance().getEncounter(new ResourceLocation(encounterId));
final ExpeditionEncounter encounter = ExpeditionEncounterListener.getEncounter(new ResourceLocation(encounterId));
if (encounter == null)
{
Log.getLogger().warn("Expedition loot table referred to encounter '{}' which does not exist.", encounterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,19 @@

/**
* Encounters are mob encounters that can be found on expeditions.
*
* @param id The id of the encounter.
* @param entityType The entity type of the encounter.
* @param damage The damage this encounter will deal.
* @param reflectingDamage The damage this encounter will reflect upon itself after dealing damage.
* @param health The health this encounter has.
* @param armor The armor level this encounter has.
* @param lootTable The loot table killing this encounter will give.
* @param xp The experience killing this encounter will give.
*/
public class ExpeditionEncounter
public record ExpeditionEncounter(ResourceLocation id, EntityType<?> entityType, float damage, float reflectingDamage, double health, int armor, ResourceLocation lootTable,
double xp)
{
/**
* The id of the encounter.
*/
private final ResourceLocation id;

/**
* The entity type of the encounter.
*/
private final EntityType<?> entityType;

/**
* The damage this encounter will deal.
*/
private final float damage;

/**
* The damage this encounter will reflect upon itself after dealing damage.
*/
private final float reflectingDamage;

/**
* The health this encounter has.
*/
private final double health;

/**
* The armor level this encounter has.
*/
private final int armor;

/**
* The loot table killing this encounter will give.
*/
private final ResourceLocation lootTable;

/**
* The experience killing this encounter will give.
*/
private final double xp;

/**
* Default constructor.
*/
public ExpeditionEncounter(
final ResourceLocation id,
final EntityType<?> entityType,
final float damage,
final float reflectingDamage,
final double health,
final int armor,
final ResourceLocation lootTable,
final double xp)
{
this.id = id;
this.entityType = entityType;
this.damage = damage;
this.reflectingDamage = reflectingDamage;
this.health = health;
this.armor = armor;
this.lootTable = lootTable;
this.xp = xp;
}

/**
* Get the id of the encounter.
*
* @return the id.
*/
public ResourceLocation getId()
{
return id;
}

/**
* Get the name of the encounter.
*
Expand All @@ -91,74 +28,4 @@ public Component getName()
{
return entityType.getDescription();
}

/**
* Get the entity type of the encounter.
*
* @return the entity type.
*/
public EntityType<?> getEntityType()
{
return entityType;
}

/**
* Get the damage this encounter will deal.
*
* @return the damage amount.
*/
public float getDamage()
{
return damage;
}

/**
* Get the damage this encounter will reflect upon itself after dealing damage.
*
* @return the reflecting damage amount.
*/
public float getReflectingDamage()
{
return reflectingDamage;
}

/**
* Get the health this encounter has.
*
* @return the health amount.
*/
public double getHealth()
{
return health;
}

/**
* Get the armor level this encounter has.
*
* @return the armor amount.
*/
public int getArmor()
{
return armor;
}

/**
* Get the loot table killing this encounter will give.
*
* @return the loot table id.
*/
public ResourceLocation getLootTable()
{
return lootTable;
}

/**
* Get the experience killing this encounter will give.
*
* @return the experience amount.
*/
public double getXp()
{
return xp;
}
}

This file was deleted.

Loading

0 comments on commit 80b4083

Please sign in to comment.