Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Sep 18, 2022
2 parents d29ae91 + 5967faa commit 94ab03b
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 37 deletions.
7 changes: 2 additions & 5 deletions src/main/java/pokecube/adventures/utils/EnergyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -199,8 +198,7 @@ public static void SiphonEvent(final SiphonTickEvent event)
{
final BlockEntity te = v.getTileEntity(world, side);
IEnergyStorage cap;
if (te != null
&& (cap = te.getCapability(ThutCaps.ENERGY, side.getOpposite()).orElse(null)) != null)
if (te != null && (cap = te.getCapability(ThutCaps.ENERGY, side.getOpposite()).orElse(null)) != null)
{
if (!cap.canReceive()) continue;
final int toSend = cap.receiveEnergy(output, true);
Expand All @@ -212,8 +210,7 @@ public static void SiphonEvent(final SiphonTickEvent event)
final BlockPos bpos = pos.pos();
final ResourceKey<Level> dim = pos.dimension();
if (dim != world.dimension()) continue;
final ChunkPos cpos = new ChunkPos(bpos);
if (!world.hasChunk(cpos.x, cpos.z)) continue;
if (!world.isLoaded(bpos)) continue;
final BlockEntity te = world.getBlockEntity(bpos);
if (te == null) continue;
IEnergyStorage cap;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/pokecube/api/entity/pokemob/ICanEvolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ default IPokemob evolve(final boolean delayed, final boolean init, final ItemSta
// change to new forme.
final IPokemob evo = this.megaEvolve(((EvolveEvent.Pre) evt).forme);
// Remove held item if it had one.
if (neededItem && stack == thisMob.getHeldItem()) evo.setHeldItem(ItemStack.EMPTY);
if (neededItem && ItemStack.isSame(stack, thisMob.getHeldItem())) evo.setHeldItem(ItemStack.EMPTY);
// Init things like moves.
evo.getMoveStats().oldLevel = data.level - 1;
evo.levelUp(evo.getLevel());
Expand Down Expand Up @@ -229,7 +229,8 @@ else if (this.getPokedexEntry().canEvolve() && thisEntity.isAlive())
if (evo != null)
{
// Clear held item if used for evolving.
if (neededItem) evo.setHeldItem(ItemStack.EMPTY);
if (neededItem && ItemStack.isSame(stack, thisMob.getHeldItem())) evo.setHeldItem(ItemStack.EMPTY);

evt = new EvolveEvent.Post(evo);
MinecraftForge.EVENT_BUS.post(evt);
// Lean any moves that should are supposed to have just
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/pokecube/compat/wearables/sided/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import pokecube.api.entity.pokemob.IPokemob;
import pokecube.api.entity.pokemob.PokemobCaps;
import pokecube.core.PokecubeItems;
import pokecube.core.items.megastuff.ItemMegawearable;
import thut.api.ModelHolder;
Expand All @@ -22,7 +26,9 @@
import thut.wearables.EnumWearable;
import thut.wearables.IActiveWearable;
import thut.wearables.ThutWearables;
import thut.wearables.events.WearableDroppedEvent;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class Common
{
public static class WearableMega implements thut.wearables.IActiveWearable, ICapabilityProvider
Expand Down Expand Up @@ -144,4 +150,11 @@ public static void registerCapabilities(final AttachCapabilitiesEvent<ItemStack>
else if (event.getObject().getItem() == PokecubeItems.POKEWATCH.get())
event.addCapability(Common.WEARABLESKEY, new WearableWatch());
}

@SubscribeEvent
public static void onWearablesDrop(WearableDroppedEvent event)
{
IPokemob mob = PokemobCaps.getPokemobFor(event.getEntity());
if (mob != null && mob.getOwnerId() != null) event.setCanceled(true);
}
}
2 changes: 2 additions & 0 deletions src/main/java/pokecube/core/ai/logic/LogicMiscUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ public void tick(final Level world)
if (!this.initHome)
{
this.initHome = true;
homes:
if (this.pokemob.getHome() != null)
{
if (!world.isLoaded(this.pokemob.getHome())) break homes;
final BlockEntity te = world.getBlockEntity(this.pokemob.getHome());
if (te instanceof NestTile nest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static Optional<AntNest> getNest(final Mob mob)
final GlobalPos pos = pos_opt.get();
final boolean notHere = pos.dimension() != world.dimension();
if (notHere) return Optional.empty();
if (!world.isLoaded(pos.pos())) return Optional.empty();
final BlockEntity tile = world.getBlockEntity(pos.pos());
if (tile instanceof NestTile nest)
{
Expand Down Expand Up @@ -87,6 +88,7 @@ protected void doTick(final ServerLevel worldIn, final Mob entityIn)

private boolean validNest(final BlockPos p, final ServerLevel worldIn, final Mob entityIn)
{
if (!entityIn.level.isLoaded(p)) return false;
final BlockEntity tile = worldIn.getBlockEntity(p);
if (!(tile instanceof NestTile nest)) return false;
return nest.isType(AntTasks.NESTLOC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run()
final long n = pois.getCountInRange(PointsOfInterest.NEST, pos.pos(), 1, PoiManager.Occupancy.ANY);
clearHive = n == 0;

if (clearHive && dist < 256 && this.nest != null)
if (clearHive && dist < 256 && this.nest != null && this.world.isLoaded(pos.pos()))
{
// Lets remake the hive.
this.world.setBlockAndUpdate(pos.pos(), PokecubeItems.NEST.get().defaultBlockState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private static List<BlockPos> getNearbyFreeHives(final Mob entityIn)

public static boolean doesHiveHaveSpace(final Mob entityIn, final BlockPos pos)
{
if (!entityIn.level.isLoaded(pos)) return false;
final BlockEntity tile = entityIn.getLevel().getBlockEntity(pos);
if (tile != null) for (final IHiveSpaceCheck checker : HiveSensor.hiveSpaceCheckers)
if (checker.canAddBee(entityIn, tile)) return true;
Expand All @@ -99,6 +100,7 @@ public static boolean doesHiveHaveSpace(final Mob entityIn, final BlockPos pos)

public static boolean tryAddToBeeHive(final Mob entityIn, final BlockPos hive)
{
if (!entityIn.level.isLoaded(hive)) return false;
final BlockEntity tile = entityIn.getLevel().getBlockEntity(hive);
if (tile != null)
for (final IHiveEnterer checker : HiveSensor.hiveEnterers) if (checker.addBee(entityIn, tile)) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static Optional<Burrow> getNest(final Mob mob)
final GlobalPos pos = pos_opt.get();
final boolean notHere = pos.dimension() != world.dimension();
if (notHere) return Optional.empty();
if (!world.isLoaded(pos.pos())) return Optional.empty();
final BlockEntity tile = world.getBlockEntity(pos.pos());
if (tile instanceof NestTile nest)
{
Expand Down Expand Up @@ -87,6 +88,7 @@ protected void doTick(final ServerLevel worldIn, final Mob entityIn)

private boolean validNest(final BlockPos p, final ServerLevel worldIn, final Mob entityIn)
{
if (!entityIn.level.isLoaded(p)) return false;
final BlockEntity tile = worldIn.getBlockEntity(p);
if (!(tile instanceof NestTile nest)) return false;
if (!nest.isType(BurrowTasks.BURROWLOC)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public void onRemove(final BlockState state, final Level world, final BlockPos p
@Override
public void tick(final BlockState state, final ServerLevel world, final BlockPos pos, final RandomSource random)
{
if (!world.isLoaded(pos)) return;
final BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity instanceof GenericBarrelTile) ((GenericBarrelTile) tileentity).recheckOpen();
if (tileentity instanceof GenericBarrelTile barrel) barrel.recheckOpen();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ public void init()
public void initModel(final ModelWrapper<Mob> model)
{
this.wrapper = model;
model.imodel = ModelFactory.create(model.model, m -> {
AnimationLoader.parse(this, model, this);
ModelFactory.create(model.model, m -> {
// Set this first in here, so that we can run parse properly.
this.wrapper.imodel = m;
AnimationLoader.parse(this, m, this);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void preValidateVelocity()
}

final Vector3 target = new Vector3();
if (this.targetEntity != null) target.set(this.targetEntity);
if (this.targetEntity != null) target.set(this.targetEntity, true);
else target.set(this.targetLocation);
if (!target.isEmpty() && this.seeking)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ public static void spawn(final IPokemob mob, final ItemStack stack, final Level
}
final EggEvent.Hatch evt = new EggEvent.Hatch(egg);
PokecubeAPI.POKEMOB_BUS.post(evt);
nests:
if (nbt.contains("nestLoc"))
{
final BlockPos pos = NbtUtils.readBlockPos(nbt.getCompound("nestLoc"));
if (!world.isLoaded(pos)) break nests;
final BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof NestTile) ((NestTile) tile).addResident(mob);
if (tile instanceof NestTile nest) nest.addResident(mob);
mob.setGeneralState(GeneralStates.EXITINGCUBE, false);
}
entity.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/pokecube/legends/blocks/containers/GenericBarrel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
public class GenericBarrel extends BaseEntityBlock
{
public static final DirectionProperty FACING = BlockStateProperties.FACING;
public static final BooleanProperty OPEN = BlockStateProperties.OPEN;
public static final BooleanProperty OPEN = BlockStateProperties.OPEN;

public GenericBarrel(final Properties props)
{
super(props);
this.registerDefaultState(this.stateDefinition.any().setValue(GenericBarrel.FACING, Direction.NORTH).setValue(
GenericBarrel.OPEN, Boolean.valueOf(false)));
this.registerDefaultState(this.stateDefinition.any().setValue(GenericBarrel.FACING, Direction.NORTH)
.setValue(GenericBarrel.OPEN, Boolean.valueOf(false)));
}

@Override
Expand All @@ -57,8 +57,8 @@ public void setPlacedBy(final Level world, final BlockPos pos, final BlockState
if (stack.hasCustomHoverName())
{
final BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity instanceof GenericBarrelTile) ((GenericBarrelTile) tileentity).setCustomName(stack
.getHoverName());
if (tileentity instanceof GenericBarrelTile)
((GenericBarrelTile) tileentity).setCustomName(stack.getHoverName());
}
}

Expand All @@ -69,8 +69,8 @@ protected void createBlockStateDefinition(final StateDefinition.Builder<Block, B
}

@Override
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos,
final Player player, final InteractionHand hand, final BlockHitResult blockRayTraceResult)
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, final Player player,
final InteractionHand hand, final BlockHitResult blockRayTraceResult)
{
if (world.isClientSide) return InteractionResult.SUCCESS;
else
Expand Down Expand Up @@ -106,8 +106,9 @@ public void onRemove(final BlockState state, final Level world, final BlockPos p
@Override
public void tick(final BlockState state, final ServerLevel world, final BlockPos pos, final RandomSource random)
{
if (!world.isLoaded(pos)) return;
final BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity instanceof GenericBarrelTile) ((GenericBarrelTile) tileentity).recheckOpen();
if (tileentity instanceof GenericBarrelTile barrel) barrel.recheckOpen();
}

@Override
Expand All @@ -120,8 +121,8 @@ public BlockState mirror(final BlockState state, final Mirror mirror)
@Override
public BlockState getStateForPlacement(final BlockPlaceContext blockItemUseContext)
{
return this.defaultBlockState().setValue(GenericBarrel.FACING, blockItemUseContext.getNearestLookingDirection()
.getOpposite());
return this.defaultBlockState().setValue(GenericBarrel.FACING,
blockItemUseContext.getNearestLookingDirection().getOpposite());
}

@Override
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/pokecube/legends/init/function/RaidCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ public static void CatchPokemobRaid(final CaptureEvent.Pre event)
final ResourceLocation id = PokecubeItems.getCubeId(event.getFilledCube());
final Entity catcher = event.pokecube.shootingEntity;

final boolean dynamaxCube = id.toString().equals("pokecube_legends:dyna");
final boolean dynamaxCube = id.toString().equals("pokecube:dynacube");
final boolean raidMob = event.mob.getPersistentData().getBoolean("pokecube_legends:raid_mob");

System.out.println(dynamaxCube+" "+raidMob);
// Catch Raids
if (raidMob) if (dynamaxCube)
if (raidMob)
{
PokecubeAPI.LOGGER.debug("Life: " + event.mob.getHealth() + "Max Life: " + event.mob.getMaxHealth());
if (event.mob.getHealth() > event.mob.getMaxHealth() / 2)
if (dynamaxCube)
{
PokecubeAPI.LOGGER.debug("Life: " + event.mob.getHealth() + "Max Life: " + event.mob.getMaxHealth());
if (event.mob.getHealth() > event.mob.getMaxHealth() / 2)
{
if (catcher instanceof Player player)
thut.lib.ChatHelper.sendSystemMessage(player, TComponent.translatable("pokecube.denied"));
event.setCanceled(true);
event.setResult(Result.DENY);
CaptureManager.onCaptureDenied(event.pokecube);
}
}
else
{
if (catcher instanceof Player player)
thut.lib.ChatHelper.sendSystemMessage(player, TComponent.translatable("pokecube.denied"));
Expand All @@ -35,14 +47,6 @@ public static void CatchPokemobRaid(final CaptureEvent.Pre event)
CaptureManager.onCaptureDenied(event.pokecube);
}
}
else
{
if (catcher instanceof Player player)
thut.lib.ChatHelper.sendSystemMessage(player, TComponent.translatable("pokecube.denied"));
event.setCanceled(true);
event.setResult(Result.DENY);
CaptureManager.onCaptureDenied(event.pokecube);
}

// No Catch normal Pokemobs
if (dynamaxCube && !raidMob)
Expand All @@ -60,7 +64,7 @@ public static void PostCatchPokemobRaid(final CaptureEvent.Post event)
final ResourceLocation id = PokecubeItems.getCubeId(event.getFilledCube());

// Catch Raids
if (id.toString().equals("pokecube_legends:dyna"))
if (id.toString().equals("pokecube:dynacube"))
{
final IPokemob pokemob = event.getCaught();
pokemob.setPokecube(PokecubeItems.getStack("pokecube"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/thut/wearables/ThutWearables.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public void dropLoot(final LivingDropsEvent event)
final ItemStack stack = cap.getStackInSlot(i);
if (!stack.isEmpty())
{
EnumWearable.takeOff(mob, stack, i);
final WearableDroppedEvent dropEvent = new WearableDroppedEvent(event, stack, i);
if (MinecraftForge.EVENT_BUS.post(dropEvent)) continue;
EnumWearable.takeOff(mob, stack, i);
final double d0 = mob.getY() - 0.3D + mob.getEyeHeight();
final ItemEntity drop = new ItemEntity(mob.getLevel(), mob.getX(), d0, mob.getZ(), stack);
final float f = mob.getRandom().nextFloat() * 0.5F;
Expand Down

0 comments on commit 94ab03b

Please sign in to comment.