Code style changes, entities fixes

This commit is contained in:
paulevsGitch 2021-07-08 00:21:47 +03:00
parent 9d604b2d25
commit 44962e18b6
377 changed files with 5038 additions and 4914 deletions

View file

@ -1,17 +1,7 @@
package ru.betterend.rituals;
import java.awt.Point;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.function.Predicate;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
@ -37,6 +27,7 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.material.Material;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blocks.BlockProperties;
import ru.betterend.BetterEnd;
import ru.betterend.blocks.EndPortalBlock;
@ -46,6 +37,13 @@ import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndFeatures;
import ru.betterend.registry.EndPortals;
import java.awt.Point;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.function.Predicate;
public class EternalRitual {
private final static Set<Point> STRUCTURE_MAP = Sets.newHashSet(
new Point(-4, -5), new Point(-4, 5), new Point(-6, 0),
@ -125,7 +123,8 @@ public class EternalRitual {
Item pItem = pedestal.getItem(0).getItem();
if (item == null) {
item = pItem;
} else if (!item.equals(pItem)) {
}
else if (!item.equals(pItem)) {
valid = false;
}
}
@ -163,10 +162,12 @@ public class EternalRitual {
try {
if (exit == null) {
initPortal(worldId, portalId);
} else {
}
else {
if (!worldId.equals(targetWorldId)) {
initPortal(worldId, portalId);
} else if (!checkFrame(targetWorld, exit.below())) {
}
else if (!checkFrame(targetWorld, exit.below())) {
Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
generatePortal(targetWorld, exit, portalAxis, portalId);
}
@ -175,7 +176,8 @@ public class EternalRitual {
activatePortal(world, center, portalId);
doEffects((ServerLevel) world, center);
active = true;
} catch (Exception ex) {
}
catch (Exception ex) {
BetterEnd.LOGGER.error("Create End portals error.", ex);
removePortal(targetWorld, exit);
removePortal(world, center);
@ -282,7 +284,7 @@ public class EternalRitual {
private BlockPos findFrame(Level world, BlockPos.MutableBlockPos startPos) {
List<BlockPos.MutableBlockPos> foundPos = findAllBlockPos(world, startPos, (SEARCH_RADIUS >> 4) + 1, FRAME,
blockState -> blockState.is(FRAME) && !blockState.getValue(ACTIVE));
for(BlockPos.MutableBlockPos testPos : foundPos) {
for (BlockPos.MutableBlockPos testPos : foundPos) {
if (checkFrame(world, testPos)) {
return testPos;
}
@ -305,7 +307,8 @@ public class EternalRitual {
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
generatePortal(targetWorld, basePos, portalAxis, portalId);
return basePos.immutable();
} else {
}
else {
Direction direction = Direction.EAST;
BlockPos.MutableBlockPos checkPos = basePos.mutable();
int radius = (int) ((SEARCH_RADIUS / multiplier) + 1);
@ -319,7 +322,7 @@ public class EternalRitual {
if (ceil < 5) continue;
checkPos.setY(ceil);
while (checkPos.getY() >= 5) {
if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
if (checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
generatePortal(targetWorld, checkPos, portalAxis, portalId);
return checkPos.immutable();
}
@ -333,7 +336,8 @@ public class EternalRitual {
}
if (targetWorld.dimension() == Level.END) {
Features.END_ISLAND.place(targetWorld, targetWorld.getChunkSource().getGenerator(), new Random(basePos.asLong()), basePos.below());
} else if (targetWorld.dimension() == Level.OVERWORLD) {
}
else if (targetWorld.dimension() == Level.OVERWORLD) {
basePos.setY(targetWorld.getChunk(basePos).getHeight(Heightmap.Types.WORLD_SURFACE, basePos.getX(), basePos.getZ()) + 1);
}
EndFeatures.BIOME_ISLAND.getFeatureConfigured().place(targetWorld, targetWorld.getChunkSource().getGenerator(), new Random(basePos.asLong()), basePos.below());
@ -410,7 +414,8 @@ public class EternalRitual {
checkPos = checkPos.east(8);
if (this.hasPedestal(checkPos)) {
this.center = initial.north(5).east(4);
} else {
}
else {
this.center = initial.north(5).west(4);
}
return;
@ -421,7 +426,8 @@ public class EternalRitual {
checkPos = checkPos.east(8);
if (this.hasPedestal(checkPos)) {
this.center = initial.south(5).east(4);
} else {
}
else {
this.center = initial.south(5).west(4);
}
return;
@ -432,7 +438,8 @@ public class EternalRitual {
checkPos = checkPos.south(8);
if (this.hasPedestal(checkPos)) {
this.center = initial.east(5).south(4);
} else {
}
else {
this.center = initial.east(5).north(4);
}
return;
@ -443,7 +450,8 @@ public class EternalRitual {
checkPos = checkPos.south(8);
if (this.hasPedestal(checkPos)) {
this.center = initial.west(5).south(4);
} else {
}
else {
this.center = initial.west(5).north(4);
}
}
@ -460,7 +468,8 @@ public class EternalRitual {
if (pedestal != null) {
if (!pedestal.hasRitual()) {
pedestal.linkRitual(this);
} else {
}
else {
EternalRitual ritual = pedestal.getRitual();
if (!ritual.equals(this)) {
pedestal.linkRitual(this);
@ -564,12 +573,11 @@ public class EternalRitual {
}
/**
* @param world World for search
* @param checkPos Start search position
* @param radius Search radius
* @param world World for search
* @param checkPos Start search position
* @param radius Search radius
* @param searchBlock Target block
* @param condition Predicate for test block states in the chunk section
*
* @param condition Predicate for test block states in the chunk section
* @return Position of the first found block or null.
*/
@Nullable
@ -583,7 +591,7 @@ public class EternalRitual {
if (section == null || !section.getStates().maybeHas(condition)) continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for(int z = 0; z < 16; z++) {
for (int z = 0; z < 16; z++) {
BlockState checkState = section.getBlockState(x, y, z);
if (checkState.is(searchBlock)) {
int worldX = (chunk.getPos().x << 4) + x;
@ -604,12 +612,11 @@ public class EternalRitual {
}
/**
* @param world World for search
* @param checkPos Start search position
* @param radius Search radius
* @param world World for search
* @param checkPos Start search position
* @param radius Search radius
* @param searchBlock Target block
* @param condition Predicate for test block states in the chunk section
*
* @param condition Predicate for test block states in the chunk section
* @return List of positions of the all found blocks or empty list.
*/
public static List<BlockPos.MutableBlockPos> findAllBlockPos(Level world, BlockPos.MutableBlockPos checkPos, int radius, Block searchBlock, Predicate<BlockState> condition) {
@ -623,7 +630,7 @@ public class EternalRitual {
if (section == null || !section.getStates().maybeHas(condition)) continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for(int z = 0; z < 16; z++) {
for (int z = 0; z < 16; z++) {
BlockState checkState = section.getBlockState(x, y, z);
if (checkState.is(searchBlock)) {
int worldX = (chunk.getPos().x << 4) + x;

View file

@ -1,9 +1,5 @@
package ru.betterend.rituals;
import java.awt.Point;
import java.util.Arrays;
import java.util.Objects;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
@ -19,8 +15,12 @@ import ru.betterend.blocks.entities.PedestalBlockEntity;
import ru.betterend.particle.InfusionParticleType;
import ru.betterend.recipe.builders.InfusionRecipe;
import java.awt.Point;
import java.util.Arrays;
import java.util.Objects;
public class InfusionRitual implements Container {
private static final Point[] PEDESTALS_MAP = new Point[] {
private static final Point[] PEDESTALS_MAP = new Point[]{
new Point(0, 3),
new Point(2, 2),
new Point(3, 0),
@ -41,14 +41,14 @@ public class InfusionRitual implements Container {
private final PedestalBlockEntity[] catalysts = new PedestalBlockEntity[8];
private final InfusionPedestalEntity input;
public InfusionRitual(InfusionPedestalEntity pedestal, Level world, BlockPos pos) {
this.input = pedestal;
this.world = world;
this.worldPos = pos;
configure();
}
public void configure() {
if (world == null || worldPos == null || world.isClientSide) return;
for (int i = 0; i < catalysts.length; i++) {
@ -57,12 +57,13 @@ public class InfusionRitual implements Container {
BlockEntity catalystEntity = world.getBlockEntity(checkPos);
if (catalystEntity instanceof PedestalBlockEntity) {
catalysts[i] = (PedestalBlockEntity) catalystEntity;
} else {
}
else {
catalysts[i] = null;
}
}
}
public boolean checkRecipe() {
if (!isValid()) return false;
InfusionRecipe recipe = world.getRecipeManager().getRecipeFor(InfusionRecipe.TYPE, this, world).orElse(null);
@ -70,7 +71,8 @@ public class InfusionRitual implements Container {
if (recipe == null) {
reset();
return false;
} else if (activeRecipe == null || recipe.getInfusionTime() != time) {
}
else if (activeRecipe == null || recipe.getInfusionTime() != time) {
updateRecipe(recipe);
}
return true;
@ -93,14 +95,14 @@ public class InfusionRitual implements Container {
time = activeRecipe != null ? activeRecipe.getInfusionTime() : 0;
progress = 0;
}
public void reset() {
activeRecipe = null;
hasRecipe = false;
resetTimer();
setChanged();
}
public void tick() {
if (isDirty) {
configure();
@ -112,7 +114,8 @@ public class InfusionRitual implements Container {
clearContent();
input.setItem(0, activeRecipe.assemble(this));
reset();
} else {
}
else {
ServerLevel serverLevel = (ServerLevel) world;
BlockPos target = worldPos.above();
double tx = target.getX() + 0.5;
@ -131,17 +134,17 @@ public class InfusionRitual implements Container {
}
}
@Override
public boolean canPlaceItem(int slot, ItemStack stack) {
return isValid();
}
public boolean isValid() {
if (world == null || world.isClientSide || worldPos == null || input == null) return false;
return Arrays.stream(catalysts).noneMatch(Objects::isNull);
}
public boolean hasRecipe() {
return hasRecipe;
}
@ -174,7 +177,8 @@ public class InfusionRitual implements Container {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return input.getItem(0);
} else {
}
else {
return catalysts[slot - 1].getItem(0);
}
}
@ -189,7 +193,8 @@ public class InfusionRitual implements Container {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return input.removeItemNoUpdate(0);
} else {
}
else {
return catalysts[slot - 1].removeItemNoUpdate(0);
}
}
@ -199,7 +204,8 @@ public class InfusionRitual implements Container {
if (slot > 8) return;
if (slot == 0) {
input.setItem(0, stack);
} else {
}
else {
catalysts[slot - 1].setItem(0, stack);
}
}
@ -220,7 +226,7 @@ public class InfusionRitual implements Container {
public boolean stillValid(Player player) {
return true;
}
public void fromTag(CompoundTag tag) {
if (tag.contains("recipe")) {
hasRecipe = tag.getBoolean("recipe");