Skip to content

Commit

Permalink
1.20.2 work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Oct 31, 2023
1 parent e654f3f commit 1c58d46
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 78 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ sourceSets {
main {
java {
srcDir 'src/main/flatbuffers/generated'
exclude "**/integration/modules/rei/**"
exclude "**/integration/modules/jei/**"
}
resources {
srcDir 'src/generated/resources'
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/client/gui/AEBaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
this.updateBeforeRender();
this.widgets.updateBeforeRender();

super.renderBackground(guiGraphics);
super.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
super.render(guiGraphics, mouseX, mouseY, partialTicks);

renderTooltips(guiGraphics, mouseX, mouseY);
Expand Down Expand Up @@ -515,8 +515,8 @@ public void setFocused(@Nullable GuiEventListener listener) {
}

@Override
public boolean mouseScrolled(double x, double y, double wheelDelta) {
if (wheelDelta != 0 && widgets.onMouseWheel(getMousePoint(x, y), wheelDelta)) {
public boolean mouseScrolled(double x, double y, double deltaX, double deltaY) {
if (deltaY != 0 && widgets.onMouseWheel(getMousePoint(x, y), deltaY)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* A Minecraft toast for a finished crafting job.
*/
public class FinishedJobToast implements Toast {
private static final ResourceLocation BACKGROUND_SPRITE = new ResourceLocation("toast/recipe");

private static final long TIME_VISIBLE = 2500;
private static final int TITLE_COLOR = 0xFF500050;
private static final int TEXT_COLOR = 0xFF000000;
Expand Down Expand Up @@ -45,13 +47,13 @@ public Visibility render(GuiGraphics guiGraphics, ToastComponent toastComponent,
var font = minecraft.font;

// stretch the middle
guiGraphics.blit(TEXTURE, 0, 0, 0, 32, this.width(), 8);
guiGraphics.blit(BACKGROUND_SPRITE, 0, 0, 0, 32, this.width(), 8);
int middleHeight = height - 16;
for (var middleY = 0; middleY < middleHeight; middleY += 16) {
var tileHeight = Math.min(middleHeight - middleY, 16);
guiGraphics.blit(TEXTURE, 0, 8 + middleY, 0, 32 + 8, this.width(), tileHeight);
guiGraphics.blit(BACKGROUND_SPRITE, 0, 8 + middleY, 0, 32 + 8, this.width(), tileHeight);
}
guiGraphics.blit(TEXTURE, 0, height - 8, 0, 32 + 32 - 8, this.width(), 8);
guiGraphics.blit(BACKGROUND_SPRITE, 0, height - 8, 0, 32 + 32 - 8, this.width(), 8);
guiGraphics.drawString(toastComponent.getMinecraft().font, GuiText.ToastCraftingJobFinishedTitle.text(), 30, 7,
TITLE_COLOR, false);
var lineY = 18;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/appeng/client/gui/me/common/MEStorageScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,14 @@ public boolean mouseClicked(double xCoord, double yCoord, int btn) {
}

@Override
public boolean mouseScrolled(double x, double y, double wheelDelta) {
if (wheelDelta != 0 && hasShiftDown()) {
public boolean mouseScrolled(double x, double y, double deltaX, double deltaY) {
if (deltaY != 0 && hasShiftDown()) {
if (this.findSlot(x, y) instanceof RepoSlot repoSlot) {
GridInventoryEntry entry = repoSlot.getEntry();
long serial = entry != null ? entry.getSerial() : -1;
final InventoryAction direction = wheelDelta > 0 ? InventoryAction.ROLL_DOWN
final InventoryAction direction = deltaY > 0 ? InventoryAction.ROLL_DOWN
: InventoryAction.ROLL_UP;
int times = (int) Math.abs(wheelDelta);
int times = (int) Math.abs(deltaY);
for (int h = 0; h < times; h++) {
final MEInteractionPacket p = new MEInteractionPacket(this.menu.containerId, serial, direction);
NetworkHandler.instance().sendToServer(p);
Expand All @@ -486,7 +486,7 @@ public boolean mouseScrolled(double x, double y, double wheelDelta) {
return true;
}
}
return super.mouseScrolled(x, y, wheelDelta);
return super.mouseScrolled(x, y, deltaX, deltaY);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/gui/widgets/AETextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void resize(int width, int height) {
}

public void selectAll() {
this.moveCursorTo(0);
this.moveCursorTo(0, false);
this.setHighlightPos(this.getMaxLength());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public OptionalLong getLongValue() {
public void setLongValue(long value) {
var internalValue = convertToInternalValue(Longs.constrainToRange(value, minValue, maxValue));
this.textField.setValue(decimalFormat.format(internalValue));
this.textField.moveCursorToEnd();
this.textField.moveCursorToEnd(false);
this.textField.setHighlightPos(0);
validate();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/client/guidebook/Guide.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import net.minecraft.world.level.validation.DirectoryValidator;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -140,7 +141,7 @@ public static void runDatapackReload() {
try {
var layeredAccess = RegistryLayer.createRegistryAccess();

PackRepository packRepository = new PackRepository(new ServerPacksSource());
PackRepository packRepository = new PackRepository(new ServerPacksSource(new DirectoryValidator(path -> false)));
net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(packRepository,
net.neoforged.neoforge.server.ServerLifecycleHooks::buildPackFinder);
packRepository.reload();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/client/guidebook/screen/GuideNavBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double dra
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
if (state != State.OPENING && state != State.OPEN) {
return false;
}

setScrollOffset((int) Math.round(scrollOffset - delta * 20));
setScrollOffset((int) Math.round(scrollOffset - deltaY * 20));
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/client/guidebook/screen/GuideScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ private LytRect getDocumentViewport() {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
if (!super.mouseScrolled(mouseX, mouseY, delta)) {
return scrollbar.mouseScrolled(mouseX, mouseY, delta);
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
if (!super.mouseScrolled(mouseX, mouseY, deltaX, deltaY)) {
return scrollbar.mouseScrolled(mouseX, mouseY, deltaX, deltaY);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double dra
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
public boolean mouseScrolled(double mouseX, double mouseY, double delta, double deltaHorizontal) {
if (this.visible) {
this.setScrollAmount((int) (this.scrollAmount - delta * 10));
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/render/tesr/InscriberTESR.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void render(InscriberBlockEntity blockEntity, float partialTicks, PoseSta
}

private static void addVertex(VertexConsumer vb, PoseStack ms, TextureAtlasSprite sprite, float x, float y,
float z, double texU, double texV, int overlayUV, int lightmapUV, Direction front) {
float z, float texU, float texV, int overlayUV, int lightmapUV, Direction front) {
vb.vertex(ms.last().pose(), x, y, z);
vb.color(1.0f, 1.0f, 1.0f, 1.0f);
vb.uv(sprite.getU(texU), sprite.getV(texV));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ public CompletableFuture<?> run(CachedOutput cache) {
if (entry.getKey().location().getNamespace().equals(AppEng.MOD_ID)) {
builder = overrides.getOrDefault(entry.getValue(), this::defaultBuilder).apply(entry.getValue());

futures.add(DataProvider.saveStable(cache, toJson(builder),
futures.add(DataProvider.saveStable(cache, LootTable.CODEC, finishBuilding(builder),
getPath(outputFolder, entry.getKey().location())));
}
}

futures.add(DataProvider.saveStable(cache, toJson(LootTable.lootTable()
var table = LootTable.lootTable()
.withPool(LootPool.lootPool()
.setRolls(UniformGenerator.between(1, 3))
.add(LootItem.lootTableItem(AEBlocks.SKY_STONE_BLOCK)))),
.add(LootItem.lootTableItem(AEBlocks.SKY_STONE_BLOCK)));
futures.add(DataProvider.saveStable(cache, LootTable.CODEC, finishBuilding(table),
getPath(outputFolder, AppEng.makeId("chests/meteorite"))));

return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
Expand Down Expand Up @@ -160,10 +161,6 @@ private Path getPath(Path root, ResourceLocation id) {
return root.resolve("data/" + id.getNamespace() + "/loot_tables/blocks/" + id.getPath() + ".json");
}

public JsonElement toJson(LootTable.Builder builder) {
return LootDataType.TABLE.parser().toJsonTree(finishBuilding(builder));
}

public LootTable finishBuilding(LootTable.Builder builder) {
return builder.setParamSet(LootContextParamSets.BLOCK).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import appeng.menu.me.common.MEStorageMenu;
import appeng.menu.me.items.CraftingTermMenu;
import appeng.util.CraftingRecipeUtil;
import net.minecraft.world.item.crafting.RecipeHolder;

public final class CraftingHelper {
private static final Comparator<GridInventoryEntry> ENTRY_COMPARATOR = Comparator
Expand All @@ -23,15 +24,15 @@ public final class CraftingHelper {
private CraftingHelper() {
}

public static void performTransfer(CraftingTermMenu menu, Recipe<?> recipe, boolean craftMissing) {
public static void performTransfer(CraftingTermMenu menu, RecipeHolder<?> recipe, boolean craftMissing) {

// We send the items in the recipe in any case to serve as a fallback in case the recipe is transient
var templateItems = findGoodTemplateItems(recipe, menu);
var templateItems = findGoodTemplateItems(recipe.value(), menu);

var recipeId = recipe.getId();
var recipeId = recipe.id();
// Don't transmit a recipe id to the server in case the recipe is not actually resolvable
// this is the case for recipes synthetically generated for JEI
if (menu.getPlayer().level().getRecipeManager().byKey(recipe.getId()).isEmpty()) {
if (menu.getPlayer().level().getRecipeManager().byKey(recipe.id()).isEmpty()) {
AELog.debug("Cannot send recipe id %s to server because it's transient", recipeId);
recipeId = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.google.common.math.LongMath;

import net.minecraft.world.item.crafting.RecipeHolder;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -96,13 +97,13 @@ public static boolean isSupportedCraftingRecipe(@Nullable Recipe<?> recipe) {
}

public static void encodeCraftingRecipe(PatternEncodingTermMenu menu,
@Nullable Recipe<?> recipe,
@Nullable RecipeHolder<?> recipe,
List<List<GenericStack>> genericIngredients,
Predicate<ItemStack> visiblePredicate) {
if (recipe != null && recipe.getType().equals(RecipeType.STONECUTTING)) {
if (recipe != null && recipe.value().getType().equals(RecipeType.STONECUTTING)) {
menu.setMode(EncodingMode.STONECUTTING);
menu.setStonecuttingRecipeId(recipe.getId());
} else if (recipe != null && recipe.getType().equals(RecipeType.SMITHING)) {
menu.setStonecuttingRecipeId(recipe.id());
} else if (recipe != null && recipe.value().getType().equals(RecipeType.SMITHING)) {
menu.setMode(EncodingMode.SMITHING_TABLE);
} else {
menu.setMode(EncodingMode.CRAFTING);
Expand All @@ -116,7 +117,7 @@ public static void encodeCraftingRecipe(PatternEncodingTermMenu menu,
if (recipe != null) {
// When we have access to a crafting recipe, we'll switch modes and try to find suitable
// ingredients based on the recipe ingredients, which allows for fuzzy-matching.
var ingredients3x3 = CraftingRecipeUtil.ensure3by3CraftingMatrix(recipe);
var ingredients3x3 = CraftingRecipeUtil.ensure3by3CraftingMatrix(recipe.value());

// Find a good match for every ingredient
for (int slot = 0; slot < ingredients3x3.size(); slot++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ public Optional<List<DefaultShapedDisplay>> getUsageFor(EntryStack<?> entry) {
}

private DefaultShapedDisplay make(ItemStack textureItem, ItemStack cableAnchor, ItemStack result) {
// This id should only be used within JEI and not really matter
ResourceLocation id = AppEng.makeId("facade/" + Item.getId(textureItem.getItem()));

var ingredients = NonNullList.withSize(9, Ingredient.EMPTY);
ingredients.set(1, Ingredient.of(cableAnchor));
ingredients.set(3, Ingredient.of(cableAnchor));
Expand All @@ -102,7 +99,7 @@ private DefaultShapedDisplay make(ItemStack textureItem, ItemStack cableAnchor,

result.setCount(4);

return new DefaultShapedDisplay(new ShapedRecipe(id, "", CraftingBookCategory.MISC, 3, 3, ingredients, result));
return new DefaultShapedDisplay(new ShapedRecipe("", CraftingBookCategory.MISC, 3, 3, ingredients, result));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public CategoryIdentifier<?> getCategoryIdentifier() {

@Override
public Optional<ResourceLocation> getDisplayLocation() {
return Optional.of(recipe.getId());
throw new UnsupportedOperationException(); // TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void setSearchText(String text) {
@Override
public boolean hasSearchFocus() {
var searchField = this.runtime.getSearchTextField();
return searchField != null && searchField.isFocused();
return searchField != null && searchField.m_93696_();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private Recipe<?> createFakeRecipe(Display display) {
ingredients.set(i, ingredient);
}

return new ShapedRecipe(AppEng.makeId("__fake_recipe"), "", CraftingBookCategory.MISC, CRAFTING_GRID_WIDTH,
return new ShapedRecipe("", CraftingBookCategory.MISC, CRAFTING_GRID_WIDTH,
CRAFTING_GRID_HEIGHT,
ingredients, ItemStack.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Map;
import java.util.UUID;

import appeng.util.Platform;
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.BlockPos;
Expand All @@ -29,6 +30,8 @@ public class FluidPickupStrategy implements PickupStrategy {
private final ServerLevel level;
private final BlockPos pos;
private final Direction side;
@Nullable
private final UUID owningPlayerId;

/**
* {@link System#currentTimeMillis()} of when the last sound/visual effect was played by this plane.
Expand All @@ -40,6 +43,7 @@ public FluidPickupStrategy(ServerLevel level, BlockPos pos, Direction side, Bloc
this.level = level;
this.pos = pos;
this.side = side;
this.owningPlayerId = owningPlayerId;
}

@Override
Expand Down Expand Up @@ -75,7 +79,8 @@ public Result tryPickup(IEnergySource energySource, PickupSink sink) {
// bucket
// This _MIGHT_ change the liquid, and if it does, and we dont have enough
// space, tough luck. you loose the source block.
var fluidContainer = bucketPickup.pickupBlock(level, pos, blockstate);
var fakePlayer = Platform.getFakePlayer(level, owningPlayerId);
var fluidContainer = bucketPickup.pickupBlock(fakePlayer, level, pos, blockstate);
var pickedUpStack = GenericContainerHelper.getContainedFluidStack(fluidContainer);
if (pickedUpStack != null && pickedUpStack.what() instanceof AEFluidKey fluidKey) {
this.storeFluid(sink, fluidKey, pickedUpStack.amount(), true);
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/appeng/parts/automation/FluidPlacementStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Set;
import java.util.UUID;

import appeng.util.Platform;
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -33,6 +34,8 @@ public class FluidPlacementStrategy implements PlacementStrategy {
private final ServerLevel level;
private final BlockPos pos;
private final Direction side;
@Nullable
private final UUID owningPlayerId;
/**
* The fluids that we tried to place unsuccessfully.
*/
Expand All @@ -47,6 +50,7 @@ public FluidPlacementStrategy(ServerLevel level, BlockPos pos, Direction side, B
this.level = level;
this.pos = pos;
this.side = side;
this.owningPlayerId = owningPlayerId;
}

@Override
Expand Down Expand Up @@ -143,7 +147,7 @@ private void playEvaporationEffect(Level level, BlockPos pos) {
/**
* Checks from {@link net.minecraft.world.item.BucketItem#emptyContents}
*/
private boolean canPlace(Level level, BlockState state, BlockPos pos, Fluid fluid) {
private boolean canPlace(ServerLevel level, BlockState state, BlockPos pos, Fluid fluid) {
if (!(fluid instanceof FlowingFluid)) {
return false;
}
Expand All @@ -154,10 +158,20 @@ private boolean canPlace(Level level, BlockState state, BlockPos pos, Fluid flui
return false;
}

return state.isAir()
|| state.canBeReplaced(fluid)
|| state.getBlock() instanceof LiquidBlockContainer liquidBlockContainer
&& liquidBlockContainer.canPlaceLiquid(level, pos, state, fluid);
if (state.isAir()) {
return true;
}

if (state.canBeReplaced(fluid)) {
return true;
}

if (state.getBlock() instanceof LiquidBlockContainer liquidBlockContainer) {
var fakePlayer = Platform.getFakePlayer(level, owningPlayerId);
return liquidBlockContainer.canPlaceLiquid(fakePlayer, level, pos, state, fluid);
}

return false;
}

/**
Expand Down
Loading

0 comments on commit 1c58d46

Please sign in to comment.