-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial transition of cold fire igniter from capability to attachment…
…. Doesn't serialize NBT by itself yet, but can be done easily now.
- Loading branch information
Showing
7 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/core/java/com/enderio/core/common/attachment/AttachmentUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.enderio.core.common.attachment; | ||
|
||
import com.enderio.core.common.capability.StrictFluidHandlerItemStack; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.neoforged.neoforge.attachment.AttachmentType; | ||
import net.neoforged.neoforge.fluids.capability.templates.FluidHandlerItemStack; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class AttachmentUtil { | ||
// TODO: NEO-PORT: Would be nice for there to be a variant that doesn't act upon the item's NBT. | ||
public static Supplier<AttachmentType<FluidHandlerItemStack>> itemFluidHandlerAttachment() { | ||
return () -> AttachmentType.builder(holder -> { | ||
if (holder instanceof ItemStack itemStack) { | ||
int capacity = 1000; | ||
if (itemStack.getItem() instanceof IItemFluidHandlerConfig attachedFluidTank) { | ||
capacity = attachedFluidTank.getCapacity(); | ||
} | ||
|
||
return new FluidHandlerItemStack(itemStack, capacity); | ||
} else { | ||
throw new IllegalStateException("Cannot attach fluid handler item to a non-item."); | ||
} | ||
}).build(); | ||
} | ||
|
||
public static Supplier<AttachmentType<StrictFluidHandlerItemStack>> strictItemFluidHandlerAttachment() { | ||
return () -> AttachmentType.builder(holder -> { | ||
if (holder instanceof ItemStack itemStack) { | ||
Predicate<Fluid> filter = f -> true; | ||
int capacity = 1000; | ||
if (itemStack.getItem() instanceof IStrictItemFluidHandlerConfig attachedFluidTank) { | ||
capacity = attachedFluidTank.getCapacity(); | ||
filter = attachedFluidTank.getFluidFilter(); | ||
} | ||
|
||
return new StrictFluidHandlerItemStack(itemStack, capacity, filter); | ||
} else { | ||
throw new IllegalStateException("Cannot attach fluid handler item to a non-item."); | ||
} | ||
}).build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/core/java/com/enderio/core/common/attachment/IItemFluidHandlerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.enderio.core.common.attachment; | ||
|
||
public interface IItemFluidHandlerConfig { | ||
int getCapacity(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/core/java/com/enderio/core/common/attachment/IStrictItemFluidHandlerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.enderio.core.common.attachment; | ||
|
||
import net.minecraft.world.level.material.Fluid; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public interface IStrictItemFluidHandlerConfig extends IItemFluidHandlerConfig { | ||
Predicate<Fluid> getFluidFilter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters