Skip to content

Commit

Permalink
Implement long versions of ItemStack and FluidTanks (#6)
Browse files Browse the repository at this point in the history
* Convert dropdown to use new non-deprecated methods

* Initial work for item and fluids to long

* Implement FluidTankHandlers

* Working guis with transition to new itemstacks

* Transfer more methods to IItemStackLong

* port FluidStackTank

* Make fluids slots functional

* Revert ItemSlot to ItemStack

will be making new ones to be like FluidSlot.

* Implement ListItemHandler

* Implement ItemStackLong handlers

* First implementation of ItemSlotLong

* Add method for slot and disable others

* Add missed comments

* Address reviews and fix style changes accidents

* Add some annotations

* Remove forgotten reference

* convert the last classes using delegate

* add new lines on end of file

* remove saved type nbt and move methods

* address reviews about style and errors

* missed enhanced forloop

* remove cache null check
  • Loading branch information
BlueWeabo authored Apr 21, 2024
1 parent 2393c40 commit eaa2eca
Show file tree
Hide file tree
Showing 42 changed files with 2,830 additions and 214 deletions.
28 changes: 14 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ charset = utf-8
end_of_line = crlf
indent_size = 4
indent_style = space
insert_final_newline = false
insert_final_newline = true
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides =
ij_visual_guides =
ij_wrap_on_typing = false

[*.java]
Expand Down Expand Up @@ -65,7 +65,7 @@ ij_java_blank_lines_before_package = 0
ij_java_block_brace_style = end_of_line
ij_java_block_comment_add_space = false
ij_java_block_comment_at_first_column = true
ij_java_builder_methods =
ij_java_builder_methods =
ij_java_call_parameters_new_line_after_left_paren = false
ij_java_call_parameters_right_paren_on_new_line = false
ij_java_call_parameters_wrap = off
Expand Down Expand Up @@ -103,8 +103,8 @@ ij_java_enum_constants_wrap = off
ij_java_extends_keyword_wrap = off
ij_java_extends_list_wrap = off
ij_java_field_annotation_wrap = split_into_lines
ij_java_field_name_prefix =
ij_java_field_name_suffix =
ij_java_field_name_prefix =
ij_java_field_name_suffix =
ij_java_finally_on_new_line = false
ij_java_for_brace_force = never
ij_java_for_statement_new_line_after_left_paren = false
Expand Down Expand Up @@ -138,8 +138,8 @@ ij_java_layout_static_imports_separately = true
ij_java_line_comment_add_space = false
ij_java_line_comment_add_space_on_reformat = false
ij_java_line_comment_at_first_column = true
ij_java_local_variable_name_prefix =
ij_java_local_variable_name_suffix =
ij_java_local_variable_name_prefix =
ij_java_local_variable_name_suffix =
ij_java_method_annotation_wrap = split_into_lines
ij_java_method_brace_style = end_of_line
ij_java_method_call_chain_wrap = off
Expand All @@ -154,15 +154,15 @@ ij_java_new_line_after_lparen_in_deconstruction_pattern = true
ij_java_new_line_after_lparen_in_record_header = false
ij_java_packages_to_use_import_on_demand = java.awt.*,javax.swing.*
ij_java_parameter_annotation_wrap = off
ij_java_parameter_name_prefix =
ij_java_parameter_name_suffix =
ij_java_parameter_name_prefix =
ij_java_parameter_name_suffix =
ij_java_parentheses_expression_new_line_after_left_paren = false
ij_java_parentheses_expression_right_paren_on_new_line = false
ij_java_place_assignment_sign_on_next_line = false
ij_java_prefer_longer_names = true
ij_java_prefer_parameters_wrap = false
ij_java_record_components_wrap = normal
ij_java_repeat_annotations =
ij_java_repeat_annotations =
ij_java_repeat_synchronized = true
ij_java_replace_instanceof_and_cast = false
ij_java_replace_null_check = true
Expand Down Expand Up @@ -252,13 +252,13 @@ ij_java_spaces_within_synchronized_parentheses = false
ij_java_spaces_within_try_parentheses = false
ij_java_spaces_within_while_parentheses = false
ij_java_special_else_if_treatment = true
ij_java_static_field_name_prefix =
ij_java_static_field_name_suffix =
ij_java_subclass_name_prefix =
ij_java_static_field_name_prefix =
ij_java_static_field_name_suffix =
ij_java_subclass_name_prefix =
ij_java_subclass_name_suffix = Impl
ij_java_ternary_operation_signs_on_next_line = false
ij_java_ternary_operation_wrap = off
ij_java_test_name_prefix =
ij_java_test_name_prefix =
ij_java_test_name_suffix = Test
ij_java_throws_keyword_wrap = off
ij_java_throws_list_wrap = off
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true

# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true

# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.21'
}


72 changes: 72 additions & 0 deletions src/main/java/com/cleanroommc/modularui/api/IFluidTankLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.cleanroommc.modularui.api;

import static com.google.common.primitives.Ints.saturatedCast;

import javax.annotation.Nullable;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidTank;

public interface IFluidTankLong extends IFluidTank {

/**
* @param maxDrain The max amount to be drained
* @param doDrain Do we actually drain the tank
* @return The amount of fluid drained
*/
long drainLong(long maxDrain, boolean doDrain);

/**
* @param fluid The fluid we want to put in
* @param amount The amount we want to put in
* @param doFill Do we actually fill the tank
* @return The amount of fluid filled into the tank
*/
long fillLong(@Nullable Fluid fluid, long amount, boolean doFill);

long getCapacityLong();

long getFluidAmountLong();

Fluid getRealFluid();

void setFluid(@Nullable Fluid fluid, long amount);

@Override
default FluidStack drain(int maxDrain, boolean doDrain) {
final FluidStack fluid = new FluidStack(getRealFluid(), 0);
fluid.amount = saturatedCast(drainLong(maxDrain, doDrain));
return fluid;
}

@Override
default int fill(FluidStack resource, boolean doFill) {
return saturatedCast(fillLong(resource.getFluid(), resource.amount, doFill));
}

@Override
default int getCapacity() {
return saturatedCast(getCapacityLong());
}

@Override
default FluidStack getFluid() {
if (getRealFluid() == null) return null;
return new FluidStack(getRealFluid(), getFluidAmount());
}

@Override
default int getFluidAmount() {
return saturatedCast(getFluidAmountLong());
}

@Override
default FluidTankInfo getInfo() {
return new FluidTankInfo(getFluid(), getCapacity());
}

IFluidTankLong copy();

}
62 changes: 62 additions & 0 deletions src/main/java/com/cleanroommc/modularui/api/IItemStackLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.cleanroommc.modularui.api;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.cleanroommc.modularui.utils.item.ItemStackLong;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public interface IItemStackLong {

/**
* @return The stacksize the item has currently
*/
long getStackSize();

/**
* @return The max stacksize of the item
*/
long getMaxStackSize();

/**
* @return The item it was created from
*/
Item getItem();

/**
* @return The damage the item has. Its meta id
*/
int getItemDamage();

/**
* @return NBT data the item holds
*/
@Nullable NBTTagCompound getTagCompound();

/**
* @param newStackSize The new stacksize the itemstack should have
*/
void setStackSize(long newStackSize);

/**
* @return The current ItemStackLong as a ItemStack, this stack shouldn't be edited as it won't reflect upon the real one
*/
@Nonnull ItemStack getAsItemStack();

boolean isItemEqual(@Nullable IItemStackLong other);

boolean hasTagCompound();

boolean isStackable();

boolean getHasSubtypes();

@Nonnull IItemStackLong copy();

@Nonnull IItemStackLong splitStack(long toSplit);

@Nonnull NBTTagCompound writeToNBT(@Nonnull NBTTagCompound nbt);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraftforge.fluids.IFluidHandler;

import javax.annotation.Nullable;


import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.cleanroommc.modularui.future;

import static com.google.common.primitives.Ints.saturatedCast;

import java.util.ArrayList;
import java.util.List;

import com.cleanroommc.modularui.api.IItemStackLong;
import com.cleanroommc.modularui.utils.item.ItemStackLong;

import net.minecraft.item.ItemStack;

public interface IItemHandlerLong extends IItemHandlerModifiable {

void setStackInSlotLong(int slot, IItemStackLong stack);

@Override
default void setStackInSlot(int slot, ItemStack stack) {
setStackInSlotLong(slot, new ItemStackLong(stack));
}

IItemStackLong extractItemLong(int slot, long amount, boolean simulate);

@Override
default ItemStack extractItem(int slot, int amount, boolean simulate) {
IItemStackLong item = extractItemLong(slot, amount, simulate);
return item == null ? null : item.getAsItemStack();
}

long getSlotLimitLong(int slot);

@Override
default int getSlotLimit(int slot) {
return saturatedCast(getSlotLimitLong(slot));
}

IItemStackLong getStackInSlotLong(int slot);

@Override
default ItemStack getStackInSlot(int slot) {
IItemStackLong item = getStackInSlotLong(slot);
return item == null ? null : item.getAsItemStack();
}

default List<IItemStackLong> getStacksLong() {
List<IItemStackLong> ret = new ArrayList<>(); for (int i = 0; i < getSlots(); i++) {
ret.add(getStackInSlotLong(i));
}
return ret;
}

IItemStackLong insertItemLong(int slot, IItemStackLong stack, boolean simulate);

@Override
default ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
IItemStackLong item = insertItemLong(slot, new ItemStackLong(stack), simulate);
return item == null ? null : item.getAsItemStack();
}

default boolean isItemValidLong(int slot, IItemStackLong stack) {
return true;
}

@Override
default boolean isItemValid(int slot, ItemStack stack) {
return isItemValidLong(slot, new ItemStackLong(stack));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface INBTSerializable<T extends NBTBase> {

T serializeNBT();

void deserializeNBT(T var1);
void deserializeNBT(T nbt);
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {

@Override
public void setStackInSlot(int slot, ItemStack stack) {
getInv().setInventorySlotContents(slot, stack);
getInv().setInventorySlotContents(slot, stack == null ? null : stack);
}

@Override
Expand Down
Loading

0 comments on commit eaa2eca

Please sign in to comment.