Skip to content

Commit

Permalink
Merge pull request #325 from Mixinors/development-1.16.3
Browse files Browse the repository at this point in the history
1.11.2
  • Loading branch information
Shnupbups authored Oct 13, 2020
2 parents 263bcc0 + c9c3b5f commit a301365
Show file tree
Hide file tree
Showing 152 changed files with 4,061 additions and 386 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.chainmailstudios.astromine.datagen.generator.recipe.set;

import net.minecraft.advancement.criterion.ImpossibleCriterion;
import net.minecraft.data.server.recipe.CookingRecipeJsonFactory;
import net.minecraft.item.Item;
import net.minecraft.recipe.Ingredient;

import com.github.chainmailstudios.astromine.datagen.material.MaterialItemType;
import com.github.chainmailstudios.astromine.datagen.material.MaterialSet;
import me.shedaniel.cloth.api.datagen.v1.RecipeData;

import java.util.Arrays;
import java.util.Collection;

public class MultiBlastingSetRecipeGenerator extends MultiCookingSetRecipeGenerator {
public MultiBlastingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output, int time, float experience) {
super(inputs, output, time, experience);
}

public MultiBlastingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output, float experience) {
this(inputs, output, 100, experience);
}

public MultiBlastingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output) {
this(inputs, output, 100, 0.1f);
}

@Override
public void generate(RecipeData recipes, MaterialSet set) {
Collection<Item> items = getInputs(set);
CookingRecipeJsonFactory
.createBlasting(
Ingredient.ofItems(items.toArray(new Item[0])),
set.getItem(output),
experience,
time)
.criterion("impossible", new ImpossibleCriterion.Conditions())
.offerTo(recipes, getRecipeId(set));
}

@Override
public String getRecipeName(MaterialSet set) {
return set.getItemIdPath(output) + "_from_blasting";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.chainmailstudios.astromine.datagen.generator.recipe.set;

import net.minecraft.item.Item;

import com.github.chainmailstudios.astromine.datagen.generator.recipe.set.base.CookingSetRecipeGenerator;
import com.github.chainmailstudios.astromine.datagen.material.MaterialItemType;
import com.github.chainmailstudios.astromine.datagen.material.MaterialSet;

import java.util.ArrayList;
import java.util.Collection;

public abstract class MultiCookingSetRecipeGenerator extends CookingSetRecipeGenerator {
private final Collection<MaterialItemType> inputs;

public MultiCookingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output, int time, float experience) {
super(inputs.stream().findFirst().get(), output, time, experience);
this.inputs = inputs;
}

public Collection<MaterialItemType> getInputs() {
return inputs;
}

public Collection<Item> getInputs(MaterialSet set) {
ArrayList<Item> items = new ArrayList<>();
for(MaterialItemType type:getInputs()) {
if(shouldGenerate(set, type)) items.add(set.getItem(type));
}
return items;
}

@Override
public boolean shouldGenerate(MaterialSet set) {
boolean hasInput = false;
for(MaterialItemType type:getInputs()) {
if(set.hasType(type)) hasInput = true;
}
return hasInput && set.hasType(output);
}

public boolean shouldGenerate(MaterialSet set, MaterialItemType type) {
return set.hasType(output) && set.hasType(type) && !(set.isFromVanilla(type) && set.isFromVanilla(output));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.chainmailstudios.astromine.datagen.generator.recipe.set;

import net.minecraft.advancement.criterion.ImpossibleCriterion;
import net.minecraft.data.server.recipe.CookingRecipeJsonFactory;
import net.minecraft.item.Item;
import net.minecraft.recipe.Ingredient;

import com.github.chainmailstudios.astromine.datagen.material.MaterialItemType;
import com.github.chainmailstudios.astromine.datagen.material.MaterialSet;
import me.shedaniel.cloth.api.datagen.v1.RecipeData;

import java.util.Arrays;
import java.util.Collection;

public class MultiSmeltingSetRecipeGenerator extends MultiCookingSetRecipeGenerator {

public MultiSmeltingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output, int time, float experience) {
super(inputs, output, time, experience);
}

public MultiSmeltingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output, float experience) {
this(inputs, output, 200, experience);
}

public MultiSmeltingSetRecipeGenerator(Collection<MaterialItemType> inputs, MaterialItemType output) {
this(inputs, output, 200, 0.1f);
}

@Override
public void generate(RecipeData recipes, MaterialSet set) {
Collection<Item> items = getInputs(set);
CookingRecipeJsonFactory
.createSmelting(
Ingredient.ofItems(items.toArray(new Item[0])),
set.getItem(output),
experience,
time)
.criterion("impossible", new ImpossibleCriterion.Conditions())
.offerTo(recipes, getRecipeId(set));
}

@Override
public String getRecipeName(MaterialSet set) {
return set.getItemIdPath(output) + "_from_smelting";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.github.chainmailstudios.astromine.common.block.entity.base;

import nerdhub.cardinal.components.api.component.ComponentProvider;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.fabricmc.fabric.api.network.PacketContext;

Expand All @@ -46,7 +47,6 @@
import com.github.chainmailstudios.astromine.AstromineCommon;
import com.github.chainmailstudios.astromine.common.block.base.BlockWithEntity;
import com.github.chainmailstudios.astromine.common.block.transfer.TransferType;
import com.github.chainmailstudios.astromine.common.component.SidedComponentProvider;
import com.github.chainmailstudios.astromine.common.component.block.entity.BlockEntityTransferComponent;
import com.github.chainmailstudios.astromine.common.component.inventory.FluidInventoryComponent;
import com.github.chainmailstudios.astromine.common.packet.PacketConsumer;
Expand All @@ -71,7 +71,7 @@
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

public abstract class ComponentBlockEntity extends net.minecraft.block.entity.BlockEntity implements SidedComponentProvider, PacketConsumer, BlockEntityClientSerializable, Tickable {
public abstract class ComponentBlockEntity extends net.minecraft.block.entity.BlockEntity implements ComponentProvider, PacketConsumer, BlockEntityClientSerializable, Tickable {
public static final Identifier TRANSFER_UPDATE_PACKET = AstromineCommon.identifier("transfer_update_packet");
protected final BlockEntityTransferComponent transferComponent = new BlockEntityTransferComponent();
protected final Map<ComponentType<?>, Component> allComponents = Maps.newHashMap();
Expand Down Expand Up @@ -113,21 +113,6 @@ public void consumePacket(Identifier identifier, PacketByteBuf buffer, PacketCon
allHandlers.get(identifier).accept(buffer, context);
}

@Override
public <T extends Component> Collection<T> getSidedComponents(Direction direction) {
if (direction == null) {
return (Collection<T>) allComponents.values();
} else {
if (getCachedState().contains(HorizontalFacingBlock.FACING)) {
return (Collection<T>) getComponentTypes().stream().map(type -> new Pair<>((ComponentType) type, (Component) getComponent(type))).filter(pair -> !transferComponent.get(pair.getLeft()).get(direction).isNone()).map(Pair::getRight).collect(Collectors.toList());
} else if (getCachedState().contains(FacingBlock.FACING)) {
return (Collection<T>) getComponentTypes().stream().map(type -> new Pair<>((ComponentType) type, (Component) getComponent(type))).filter(pair -> !transferComponent.get(pair.getLeft()).get(direction).isNone()).map(Pair::getRight).collect(Collectors.toList());
} else {
return Lists.newArrayList();
}
}
}

@Override
public boolean hasComponent(ComponentType<?> componentType) {
return allComponents.containsKey(componentType) || componentType == AstromineComponentTypes.BLOCK_ENTITY_TRANSFER_COMPONENT;
Expand Down Expand Up @@ -194,11 +179,10 @@ public void tick() {

for (Direction offsetDirection : Direction.values()) {
BlockPos neighborPos = getPos().offset(offsetDirection);
BlockState neighborState = world.getBlockState(neighborPos);

net.minecraft.block.entity.BlockEntity neighborBlockEntity = world.getBlockEntity(neighborPos);
if (neighborBlockEntity != null) {
SidedComponentProvider neighborProvider = SidedComponentProvider.fromBlockEntity(neighborBlockEntity);
if (neighborBlockEntity instanceof ComponentProvider) {
ComponentProvider neighborProvider = (ComponentProvider) neighborBlockEntity;
Direction neighborDirection = offsetDirection.getOpposite();
BlockEntityTransferComponent neighborTransferComponent = neighborProvider != null ? neighborProvider.getComponent(AstromineComponentTypes.BLOCK_ENTITY_TRANSFER_COMPONENT) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;

import com.github.chainmailstudios.astromine.common.component.SidedComponentProvider;
import com.github.chainmailstudios.astromine.common.component.inventory.FluidInventoryComponent;
import com.github.chainmailstudios.astromine.registry.AstromineComponentTypes;

public abstract class ComponentEnergyFluidBlockEntity extends ComponentEnergyBlockEntity implements SidedComponentProvider, BlockEntityClientSerializable {
public abstract class ComponentEnergyFluidBlockEntity extends ComponentEnergyBlockEntity {
protected final FluidInventoryComponent fluidComponent = createFluidComponent();

public ComponentEnergyFluidBlockEntity(Block energyBlock, BlockEntityType<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@

import net.minecraft.block.entity.BlockEntityType;

import com.github.chainmailstudios.astromine.common.component.SidedComponentProvider;
import com.github.chainmailstudios.astromine.common.component.inventory.FluidInventoryComponent;
import com.github.chainmailstudios.astromine.registry.AstromineComponentTypes;

public abstract class ComponentFluidBlockEntity extends ComponentBlockEntity implements SidedComponentProvider, BlockEntityClientSerializable {
public abstract class ComponentFluidBlockEntity extends ComponentBlockEntity {
protected final FluidInventoryComponent fluidComponent = createFluidComponent();

public ComponentFluidBlockEntity(BlockEntityType<?> type) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ default boolean canExtract(@Nullable Direction direction, FluidVolume volume, in

default TypedActionResult<FluidVolume> insert(Direction direction, FluidVolume volume) {
Optional<Map.Entry<Integer, FluidVolume>> matchingVolumeOptional = this.getContents().entrySet().stream().filter(entry -> {
return canInsert(direction, entry.getValue(), entry.getKey()) && entry.getValue().canAccept(volume.getFluid());
return canInsert(direction, volume, entry.getKey()) && entry.getValue().canAccept(volume.getFluid());
}).findFirst();

if (matchingVolumeOptional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package com.github.chainmailstudios.astromine.common.lba;

import com.github.chainmailstudios.astromine.common.component.block.entity.BlockEntityTransferComponent;
import nerdhub.cardinal.components.api.component.ComponentProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.Fluid;
Expand All @@ -42,7 +44,6 @@
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
import alexiil.mc.lib.attributes.fluid.volume.FluidKeys;
import com.github.chainmailstudios.astromine.common.component.SidedComponentProvider;
import com.github.chainmailstudios.astromine.common.component.inventory.FluidInventoryComponent;
import com.github.chainmailstudios.astromine.common.volume.fluid.FluidVolume;
import com.github.chainmailstudios.astromine.common.volume.fraction.Fraction;
Expand All @@ -63,17 +64,22 @@ private static <T> void appendAdder(Attribute<T> attribute) {
private static <T> void append(World world, BlockPos blockPos, BlockState state, AttributeList<T> list) {
BlockEntity blockEntity = world.getBlockEntity(blockPos);

if (blockEntity != null) {
SidedComponentProvider sidedComponentProvider = SidedComponentProvider.fromBlockEntity(blockEntity);
if (blockEntity instanceof ComponentProvider) {
ComponentProvider componentProvider = (ComponentProvider) blockEntity;

if (sidedComponentProvider != null) {
@Nullable
Direction direction = list.getTargetSide();
@Nullable
Direction direction = list.getTargetSide();

FluidInventoryComponent component = sidedComponentProvider.getSidedComponent(direction, AstromineComponentTypes.FLUID_INVENTORY_COMPONENT);
if (direction != null) {
BlockEntityTransferComponent transferComponent = componentProvider.getComponent(AstromineComponentTypes.BLOCK_ENTITY_TRANSFER_COMPONENT);

if (component != null) {
list.offer(new LibBlockAttributesWrapper(component));
// This does not check canInsert or canExtract; because I do not know how the hell to do that with LBA.
if (transferComponent != null && !transferComponent.get(AstromineComponentTypes.FLUID_INVENTORY_COMPONENT).get(direction).isNone()) {
FluidInventoryComponent component = componentProvider.getComponent(AstromineComponentTypes.FLUID_INVENTORY_COMPONENT);

if (component != null) {
list.offer(new LibBlockAttributesWrapper(component));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@

package com.github.chainmailstudios.astromine.common.network.type;

import net.minecraft.block.FacingBlock;
import net.minecraft.block.HorizontalFacingBlock;
import nerdhub.cardinal.components.api.component.ComponentProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.state.property.Property;
import net.minecraft.util.Pair;
import net.minecraft.util.math.Direction;

import com.github.chainmailstudios.astromine.common.block.transfer.TransferType;
import com.github.chainmailstudios.astromine.common.component.SidedComponentProvider;
import com.github.chainmailstudios.astromine.common.component.block.entity.BlockEntityTransferComponent;
import com.github.chainmailstudios.astromine.common.component.inventory.FluidInventoryComponent;
import com.github.chainmailstudios.astromine.common.network.NetworkInstance;
Expand All @@ -57,20 +54,14 @@ public void tick(NetworkInstance instance) {
BlockEntity blockEntity = instance.getWorld().getBlockEntity(memberNode.getBlockPos());
NetworkMember networkMember = NetworkMemberRegistry.get(blockEntity);

if (blockEntity instanceof SidedComponentProvider && networkMember.acceptsType(this)) {
SidedComponentProvider provider = SidedComponentProvider.fromBlockEntity(blockEntity);
if (blockEntity instanceof ComponentProvider && networkMember.acceptsType(this)) {
ComponentProvider provider = (ComponentProvider) blockEntity;

FluidInventoryComponent fluidComponent = provider.getSidedComponent(memberNode.getDirection(), AstromineComponentTypes.FLUID_INVENTORY_COMPONENT);
FluidInventoryComponent fluidComponent = provider.getComponent(AstromineComponentTypes.FLUID_INVENTORY_COMPONENT);

BlockEntityTransferComponent transferComponent = provider.getComponent(AstromineComponentTypes.BLOCK_ENTITY_TRANSFER_COMPONENT);

before:
if (fluidComponent != null && transferComponent != null) {
Property<Direction> property = blockEntity.getCachedState().contains(HorizontalFacingBlock.FACING) ? HorizontalFacingBlock.FACING : blockEntity.getCachedState().contains(FacingBlock.FACING) ? FacingBlock.FACING : null;

if (!blockEntity.getCachedState().contains(property))
break before;

TransferType type = transferComponent.get(AstromineComponentTypes.FLUID_INVENTORY_COMPONENT).get(memberNode.getDirection());

if (!type.isDisabled()) {
Expand Down
Loading

0 comments on commit a301365

Please sign in to comment.