Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoHuNao committed Nov 8, 2023
1 parent dd39fe6 commit f12f887
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.pancake.surviving_the_aftermath.api;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;

public interface PortalShapeAccessor {
//bottomLeft
BlockPos survivingTheAftermath$getBottomLeft();

//height
int survivingTheAftermath$getHeight();

//width
int survivingTheAftermath$getWidth();

//rightDir
Direction survivingTheAftermath$getRightDir();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@
import com.pancake.surviving_the_aftermath.SurvivingTheAftermath;
import com.pancake.surviving_the_aftermath.api.aftermath.AftermathManager;
import com.pancake.surviving_the_aftermath.common.capability.AftermathCap;
import com.pancake.surviving_the_aftermath.common.init.ModItems;
import com.pancake.surviving_the_aftermath.common.init.ModTags;
import com.pancake.surviving_the_aftermath.common.init.ModVillagers;
import com.pancake.surviving_the_aftermath.common.util.RegistryUtil;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.storage.ServerLevelData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.pancake.surviving_the_aftermath.common.init.ModSoundEvents;
import com.pancake.surviving_the_aftermath.common.init.ModStructures;
import com.pancake.surviving_the_aftermath.common.raid.NetherRaid;
import com.pancake.surviving_the_aftermath.common.raid.api.BaseRaid;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.Registries;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.portal.PortalShape;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand Down Expand Up @@ -75,7 +77,16 @@ public static void onRaidVictory(AftermathEvent.Victory event) {
ModSoundEvents.ORCHELIAS_VOX.get(), SoundSource.NEUTRAL, 3.0F, 1.0F, level.random.nextLong());
}
});
}

@SubscribeEvent
public static void joinRaid(EntityJoinLevelEvent event) {
AftermathManager.getInstance().getAftermathMap().values().stream()
.filter(aftermath -> aftermath instanceof BaseRaid<?>)
.map(aftermath -> (BaseRaid<?>) aftermath)
.forEach(raid -> raid.join(event.getEntity()));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public class VillagerSubscriber {
public static void addCustomTrades(VillagerTradesEvent event) {
final ItemStack emerald = new ItemStack(Items.EMERALD, 2);
final ItemStack diamond = new ItemStack(Items.DIAMOND, 1);
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades1 = event.getTrades();
if (event.getType() == ModVillagers.RELIC_DEALER.get()) {
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = event.getTrades();
trades.get(1).add((trader, random) -> enchantBookForNetherCore(random));
trades1.get(1).add((trader, random) -> enchantBookForNetherCore(random));
}
if (event.getType() == VillagerProfession.BUTCHER) {
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = event.getTrades();
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = trades1;
ItemStack rawFalukorv = new ItemStack(ModItems.RAW_FALUKORV.get(), 1);
trades.get(4).add((trader, random) -> newOffer(emerald, rawFalukorv));
trades.get(5).add((trader, random) -> newOffer(diamond, rawFalukorv));
}
if (event.getType() == VillagerProfession.FARMER) {
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = event.getTrades();
Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = trades1;
for (Item item : RegistryUtil.getKnownItems()) {
if (item.isEdible()) {
ItemStack foodStack = item.getDefaultInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.pancake.surviving_the_aftermath.common.mixin;

import com.pancake.surviving_the_aftermath.api.PortalShapeAccessor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.portal.PortalShape;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(PortalShape.class)
public class PortalShapeMixin implements PortalShapeAccessor {
//bottomLeft
@Shadow
private BlockPos bottomLeft;

//height
@Shadow
private int height;

//width
@Final
@Shadow
private int width;

//rightDir
@Final
@Shadow
private Direction rightDir;


@Override
public BlockPos survivingTheAftermath$getBottomLeft() {
return bottomLeft;
}

@Override
public int survivingTheAftermath$getHeight() {
return height;
}

@Override
public int survivingTheAftermath$getWidth() {
return width;
}

@Override
public Direction survivingTheAftermath$getRightDir() {
return rightDir;
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pancake.surviving_the_aftermath.common.raid;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.pancake.surviving_the_aftermath.SurvivingTheAftermath;
import com.pancake.surviving_the_aftermath.api.AftermathState;
import com.pancake.surviving_the_aftermath.api.Constant;
Expand All @@ -10,12 +10,14 @@
import com.pancake.surviving_the_aftermath.api.base.BaseAftermathModule;
import com.pancake.surviving_the_aftermath.api.module.IEntityInfoModule;
import com.pancake.surviving_the_aftermath.common.init.ModStructures;
import com.pancake.surviving_the_aftermath.api.PortalShapeAccessor;
import com.pancake.surviving_the_aftermath.common.raid.api.BaseRaid;
import com.pancake.surviving_the_aftermath.common.raid.module.NetherRaidModule;
import com.pancake.surviving_the_aftermath.common.structure.NetherRaidStructure;
import com.pancake.surviving_the_aftermath.common.tracker.RaidMobBattleTracker;
import com.pancake.surviving_the_aftermath.common.tracker.RaidPlayerBattleTracker;
import com.pancake.surviving_the_aftermath.common.util.AftermathEventUtil;
import com.pancake.surviving_the_aftermath.common.util.RandomUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
Expand All @@ -35,6 +37,7 @@
import net.minecraft.world.entity.monster.Slime;
import net.minecraft.world.entity.monster.hoglin.Hoglin;
import net.minecraft.world.entity.monster.piglin.AbstractPiglin;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -48,16 +51,13 @@
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.function.Predicate;

public class NetherRaid extends BaseRaid<NetherRaidModule> {
public static final String IDENTIFIER = "nether_raid";
private static final ResourceLocation BARS_RESOURCE = SurvivingTheAftermath.asResource("textures/gui/nether_raid_bars.png");
protected List<BlockPos> spawnPos = Lists.newArrayList();
protected Set<BlockPos> spawnPos = Sets.newHashSet();
private int readyTime;
private static final int MAX_REWARD_TIME = 10 * 20;
private int rewardTime = MAX_REWARD_TIME;
Expand Down Expand Up @@ -133,7 +133,7 @@ public int[] getBarsOffset() {

@Override
public void spawnRewards() {
BlockPos blockPos = spawnPos.get(level.random.nextInt(spawnPos.size()));
BlockPos blockPos = RandomUtils.getRandomElement(spawnPos);
Direction dir = Direction.Plane.HORIZONTAL.stream().filter(d -> level.isEmptyBlock(blockPos.relative(d))
&& !spawnPos.contains(blockPos.relative(d))).findFirst().orElse(Direction.UP);
Vec3 vec = Vec3.atCenterOf(blockPos);
Expand Down Expand Up @@ -247,10 +247,12 @@ protected List<LazyOptional<Entity>> spawnEntities(IEntityInfoModule module) {
for (LazyOptional<Entity> lazyOptional : arrayList) {
lazyOptional.ifPresent(entity -> {
if (entity instanceof Mob mob){
BlockPos blockPos = spawnPos.get(level.random.nextInt(spawnPos.size()));
mob.moveTo(blockPos.getX() + 1, blockPos.getY(), blockPos.getZ() + 1);
BlockPos blockPos = RandomUtils.getRandomElement(spawnPos);
mob.moveTo(blockPos.getX() + 0.5, blockPos.getY() , blockPos.getZ()+ 0.5);
mob.setPersistenceRequired();
mob.getBrain().setMemory(MemoryModuleType.ANGRY_AT, randomPlayersUnderAttack().getUUID());
Player target = randomPlayersUnderAttack();
mob.getBrain().setMemory(MemoryModuleType.ANGRY_AT, target.getUUID());
mob.setTarget(target);

for (var slot : EquipmentSlot.values()) {
mob.setDropChance(slot, 0);
Expand All @@ -269,6 +271,8 @@ protected List<LazyOptional<Entity>> spawnEntities(IEntityInfoModule module) {
if (entity instanceof Ghast ghast) {
ghast.setPos(ghast.getX(), ghast.getY() + 20, ghast.getZ());
}


enemies.add(mob.getUUID());
level.addFreshEntity(entity);
}
Expand All @@ -277,6 +281,8 @@ protected List<LazyOptional<Entity>> spawnEntities(IEntityInfoModule module) {
return arrayList;
}



protected void spawnWave() {
if (enemies.isEmpty() && state == AftermathState.ONGOING){
LOGGER.info(getUniqueIdentifier() +": spawn wave " + currentWave);
Expand Down Expand Up @@ -312,16 +318,14 @@ protected void checkNextWave(){

protected void setSpawnPos(PortalShape portalShape){
spawnPos.clear();
try {
BlockPos bottomLeft = SurvivingTheAftermath.getPrivateField(portalShape, "bottomLeft", BlockPos.class);
int height = SurvivingTheAftermath.getPrivateField(portalShape, "height", Integer.class);
int width = SurvivingTheAftermath.getPrivateField(portalShape, "width", Integer.class);
Direction rightDir = SurvivingTheAftermath.getPrivateField(portalShape, "rightDir", Direction.class);
BlockPos.betweenClosed(bottomLeft, bottomLeft.relative(Direction.UP, height - 1).relative(rightDir, width - 1))
spawnPos.add(centerPos);
PortalShapeAccessor portalShapeMixin = (PortalShapeAccessor ) portalShape;
BlockPos bottomLeft = portalShapeMixin.survivingTheAftermath$getBottomLeft();
int height = portalShapeMixin.survivingTheAftermath$getHeight();
int width = portalShapeMixin.survivingTheAftermath$getWidth();
Direction rightDir = portalShapeMixin.survivingTheAftermath$getRightDir();
BlockPos.betweenClosed(bottomLeft, bottomLeft.relative(Direction.UP, height - 1).relative(rightDir, width - 1))
.forEach(blockPos -> spawnPos.add(new BlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ())));
} catch (IllegalAccessException | NoSuchFieldException e) {
LOGGER.error("NetherRaid setSpawnPos error: " + e);
}
}

@Override
Expand All @@ -332,6 +336,11 @@ public void bindTrackers() {
.forEach(this::addTracker);
}

@Override
public boolean join(Entity entity) {
return entity.getType() == EntityType.MAGMA_CUBE && super.join(entity);
}

public static class Factory implements IAftermathFactory {
@Override
public IAftermath<BaseAftermathModule> create(ServerLevel level, CompoundTag compound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.mojang.logging.LogUtils;
import com.pancake.surviving_the_aftermath.api.AftermathState;
import com.pancake.surviving_the_aftermath.api.Constant;
import com.pancake.surviving_the_aftermath.api.IAftermath;
import com.pancake.surviving_the_aftermath.api.base.BaseAftermath;
Expand Down Expand Up @@ -86,4 +87,9 @@ public Player randomPlayersUnderAttack(){
}


public boolean join(Entity entity) {
return state == AftermathState.ONGOING
&& Math.sqrt(entity.blockPosition().distSqr(centerPos)) < getRadius()
&& enemies.add(entity.getUUID());
}
}
5 changes: 3 additions & 2 deletions src/main/resources/surviving_the_aftermath.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"minVersion": "0.8",
"package": "com.pancake.surviving_the_aftermath.common.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "SurvivingTheAftermath.refmap.json",
"refmap": "surviving_the_aftermath.refmap.json",
"mixins": [

"PortalShapeMixin",
"VillagerMixin"
],
"client": [
],
Expand Down

0 comments on commit f12f887

Please sign in to comment.