-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add flopper block - Update mod resources - Apply fixes to tinted glass (blocktags, redstone fixes and so) - Refactor Data Gen code
- Loading branch information
1 parent
d0f3283
commit e7d5271
Showing
38 changed files
with
924 additions
and
15 deletions.
There are no files selected for viewing
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
70 changes: 70 additions & 0 deletions
70
src/main/java/me/monkeykiller/v2_0_rediscovered/common/floppers/FlopperBlock.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,70 @@ | ||
package me.monkeykiller.v2_0_rediscovered.common.floppers; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.DispenserBlock; | ||
import net.minecraft.block.dispenser.DispenserBehavior; | ||
import net.minecraft.block.entity.*; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPointer; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.WorldEvents; | ||
import org.slf4j.Logger; | ||
|
||
public class FlopperBlock extends DispenserBlock { | ||
private static final DispenserBehavior FLOPPER_DISPENSER_BEHAVIOR = new FlopperItemDispenserBehavior(); | ||
|
||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
public FlopperBlock(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
protected DispenserBehavior getBehaviorForItem(ItemStack stack) { | ||
return FLOPPER_DISPENSER_BEHAVIOR; | ||
} | ||
|
||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new FlopperBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
protected void dispense(ServerWorld world, BlockState state, BlockPos pos) { | ||
ItemStack itemStack2; | ||
DispenserBlockEntity dispenserBlockEntity = world.getBlockEntity(pos, V2_0_Rediscovered.FLOPPER_BLOCK_ENTITY).orElse(null); | ||
if (dispenserBlockEntity == null) { | ||
LOGGER.warn("Ignoring dispensing attempt for Flopper without matching block entity at {}", pos); | ||
return; | ||
} | ||
BlockPointer blockPointer = new BlockPointer(world, pos, state, dispenserBlockEntity); | ||
int i = dispenserBlockEntity.chooseNonEmptySlot(world.random); | ||
if (i < 0) { | ||
world.syncWorldEvent(WorldEvents.DISPENSER_FAILS, pos, 0); | ||
return; | ||
} | ||
ItemStack itemStack = dispenserBlockEntity.getStack(i); | ||
if (itemStack.isEmpty()) { | ||
return; | ||
} | ||
Direction direction = world.getBlockState(pos).get(FACING); | ||
Inventory inventory = HopperBlockEntity.getInventoryAt(world, pos.offset(direction)); | ||
if (inventory == null) { | ||
itemStack2 = FLOPPER_DISPENSER_BEHAVIOR.dispense(blockPointer, itemStack); | ||
} else { | ||
itemStack2 = HopperBlockEntity.transfer(dispenserBlockEntity, inventory, itemStack.copy().split(1), direction.getOpposite()); | ||
if (itemStack2.isEmpty()) { | ||
itemStack2 = itemStack.copy(); | ||
itemStack2.decrement(1); | ||
} else { | ||
itemStack2 = itemStack.copy(); | ||
} | ||
} | ||
dispenserBlockEntity.setStack(i, itemStack2); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/me/monkeykiller/v2_0_rediscovered/common/floppers/FlopperBlockEntity.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,18 @@ | ||
package me.monkeykiller.v2_0_rediscovered.common.floppers; | ||
|
||
import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.DispenserBlockEntity; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class FlopperBlockEntity extends DispenserBlockEntity { | ||
public FlopperBlockEntity(BlockPos pos, BlockState state) { | ||
super(V2_0_Rediscovered.FLOPPER_BLOCK_ENTITY, pos, state); | ||
} | ||
|
||
@Override | ||
protected Text getContainerName() { | ||
return Text.translatable("container.flopper"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../java/me/monkeykiller/v2_0_rediscovered/common/floppers/FlopperItemDispenserBehavior.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,16 @@ | ||
package me.monkeykiller.v2_0_rediscovered.common.floppers; | ||
|
||
import net.minecraft.block.dispenser.ItemDispenserBehavior; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.util.math.BlockPointer; | ||
|
||
public class FlopperItemDispenserBehavior extends ItemDispenserBehavior { | ||
@Override | ||
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) { | ||
var fishStack = new ItemStack(Items.COD, stack.getCount()); | ||
super.dispenseSilently(pointer, fishStack); | ||
stack.decrement(1); | ||
return stack; | ||
} | ||
} |
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
24 changes: 16 additions & 8 deletions
24
src/main/java/me/monkeykiller/v2_0_rediscovered/datagen/ModTagProvider.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 |
---|---|---|
@@ -1,26 +1,34 @@ | ||
package me.monkeykiller.v2_0_rediscovered.datagen; | ||
|
||
import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.BlockItem; | ||
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.registry.tag.BlockTags; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered.*; | ||
|
||
public class ModTagProvider extends FabricTagProvider.BlockTagProvider { | ||
public ModTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) { | ||
super(output, registriesFuture); | ||
} | ||
|
||
@Override | ||
protected void configure(RegistryWrapper.WrapperLookup arg) { | ||
getOrCreateTagBuilder(BlockTags.IMPERMEABLE) | ||
.add(V2_0_Rediscovered.TINTED_GLASS_ITEMS | ||
.values().stream() | ||
.map(BlockItem::getBlock) | ||
.toArray(Block[]::new)); | ||
getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE).add(FLOPPER_BLOCK); | ||
configureColoredTintedGlassTags(); | ||
} | ||
|
||
private void configureColoredTintedGlassTags() { | ||
var impermeableTag = getOrCreateTagBuilder(BlockTags.IMPERMEABLE); | ||
var glassBlocksTag = getOrCreateTagBuilder(ConventionalBlockTags.GLASS_BLOCKS); | ||
|
||
for (var blockItem : TINTED_GLASS_ITEMS.values()) { | ||
var block = blockItem.getBlock(); | ||
impermeableTag.add(block); | ||
glassBlocksTag.add(block); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/resources/assets/v2_0_rediscovered/blockstates/flopper.json
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,26 @@ | ||
{ | ||
"variants": { | ||
"facing=down": { | ||
"model": "v2_0_rediscovered:block/flopper_vertical", | ||
"x": 180 | ||
}, | ||
"facing=east": { | ||
"model": "v2_0_rediscovered:block/flopper", | ||
"y": 90 | ||
}, | ||
"facing=north": { | ||
"model": "v2_0_rediscovered:block/flopper" | ||
}, | ||
"facing=south": { | ||
"model": "v2_0_rediscovered:block/flopper", | ||
"y": 180 | ||
}, | ||
"facing=up": { | ||
"model": "v2_0_rediscovered:block/flopper_vertical" | ||
}, | ||
"facing=west": { | ||
"model": "v2_0_rediscovered:block/flopper", | ||
"y": 270 | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/resources/assets/v2_0_rediscovered/models/block/flopper.json
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,8 @@ | ||
{ | ||
"parent": "minecraft:block/orientable", | ||
"textures": { | ||
"front": "minecraft:block/dropper_front", | ||
"side": "minecraft:block/furnace_side", | ||
"top": "minecraft:block/furnace_top" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/v2_0_rediscovered/models/block/flopper_vertical.json
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,7 @@ | ||
{ | ||
"parent": "minecraft:block/orientable_vertical", | ||
"textures": { | ||
"front": "minecraft:block/dropper_front_vertical", | ||
"side": "minecraft:block/furnace_top" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/v2_0_rediscovered/models/item/flopper.json
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,3 @@ | ||
{ | ||
"parent": "v2_0_rediscovered:block/flopper" | ||
} |
Oops, something went wrong.