Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sforzando.bttc.arch;
- public enum RotationType {
- NONE(false, false),
- CLOCKWISE(true, false),
- COUNTERCLOCKWISE(true, true);
- private final boolean isRotating;
- private final boolean isCounter;
- private RotationType (boolean b1, boolean b2) {
- this.isRotating = b1;
- this.isCounter = b2;
- }
- public static RotationType getRotationAt (World world, BlockPos pos, Direction dir) {
- if (!(world.getBlockState(pos.offset(1L, dir)).getBlock() instanceof MechanicalPowerTransferBlock)) return RotationType.NONE;
- MechanicalPowerTransferBlock mpt = (MechanicalPowerTransferBlock)world.getBlockState(pos.offset(1L, dir)).getBlock();
- return mpt.getRotationType(world, pos.offset(1L, dir), dir.getOpposite());
- }
- }
- package com.sforzando.bttc.block;
- public interface MechanicalPowerTransferBlock {
- public RotationType getRotation (World world, BlockPos pos, Direction toward);
- }
- public class AxleBlock extends FacingBlock implements MechanicalPowerTransferBlock {
- public AxleBlock (AbstractBlock.Settings settings) {
- super (settings);
- this.setDefaultState(this.getStateManager().getDefaultState().with(FacingBlock.FACING, Direction.UP));
- }
- public BlockState getPlacementState (ItemPlacementContext ctx) {
- return this.getStateManager().getDefaultState().with(FacingBlock.FACING, ctx.getSide());
- }
- public RotationType getRotation (World world, BlockPos pos, Direction toward) {
- return ((world.getBlockState(pos).hasProperty(FacingBlock.FACING) && toward.getAxis() == world.getBlockState(pos).getValue(FacingBlock.FACING).getAxis()) || this.shouldSupplyPower(world, pos)) ? RotationType.getRotationAt(world, pos, toward.getOpposite()) : RotationType.NONE;
- }
- public boolean shouldSupplyPower (World world, BlockPos pos) {
- if (world.getEntitiesOfClass(WindmillEntity.class, Box.of(pos)).size() > 0) return true;
- if (world.getEntitiesOfClass(VerticalWindmillEntity.class, Box.of(pos)).size() > 0) return true;
- if (world.getEntitiesOfClass(WaterWheelEntity.class, Box.of(pos)).size() > 0) return true;
- return false;
- }
- }
- public class GearboxBlock extends FacingBlock implements MechanicalPowerTransferBlock {
- public GearboxBlock (AbstractBlock.Settings settings) {
- super (settings);
- this.setDefaultState(this.getStateManager().getDefaultState().with(FacingBlock.FACING, Direction.UP));
- }
- public BlockState getPlacementState (ItemPlacementContext ctx) {
- return this.getStateManager().getDefaultState().with(FacingBlock.FACING, ctx.getNearestFacingDirection());
- }
- public RotationType getRotation (World world, BlockPos pos, Direction toward) {
- return (world.getBlockState(pos).hasProperty(FacingBlock.FACING) && toward != world.getBlockState(pos).getValue(FacingBlock.FACING)) ? RotationType.getRotationAt(world, pos, world.getBlockState(pos).getValue(FacingBlock.FACING)) : RotationType.NONE;
- }
- }
- public class ClutchBlock extends FacingBlock implements MechanicalPowerTransferBlock {
- public ClutchBlock (AbstractBlock.Settings settings) {
- super (settings);
- this.setDefaultState(this.getStateManager().getDefaultState().with(FacingBlock.FACING, Direction.UP));
- }
- public BlockState getPlacementState (ItemPlacementContext ctx) {
- return this.getStateManager().getDefaultState().with(FacingBlock.FACING, ctx.getNearestFacingDirection());
- }
- public RotationType getRotation (World world, BlockPos pos, Direction toward) {
- return (world.getBlockState(pos).hasProperty(FacingBlock.FACING) && toward != world.getBlockState(pos).getValue(FacingBlock.FACING) && !world.isReceivingRedstonePower(pos)) ? RotationType.getRotationAt(world, pos, world.getBlockState(pos).getValue(FacingBlock.FACING)) : RotationType.NONE;
- }
- }
- public class SawBlock extends FacingBlock implements MechanicalPowerTransferBlock {
- public static RecipeType<SawBlock.Recipe<SawBlock.Recipe.Input<Block>>>> RECIPE_TYPE = getRecipeType();
- public SawBlock (AbstractBlock.Settings settings) {
- super (settings);
- this.setDefaultState(this.getStateManager().getDefaultState().with(FacingBlock.FACING, Direction.UP));
- }
- public BlockState getPlacementState (ItemPlacementContext ctx) {
- return this.getStateManager().getDefaultState().with(FacingBlock.FACING, ctx.getNearestFacingDirection());
- }
- public RotationType getRotation (World world, BlockPos pos, Direction toward) {
- return (world.getBlockState(pos).hasProperty(FacingBlock.FACING) && toward != world.getBlockState(pos).getValue(FacingBlock.FACING) && !world.isReceivingRedstonePower(pos)) ? RotationType.getRotationAt(world, pos, world.getBlockState(pos).getValue(FacingBlock.FACING)) : RotationType.NONE;
- }
- public void neighborUpdate (BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
- super (state, world, pos, sourceBlock, sourcePos, notify);
- if (!state.hasProperty(FacingBlock.FACING) || pos.offset(1L, state.getValue(FacingBlock.FACING)) != sourcePos) return;
- Optional<RecipeHolder<SawRecipe>> sawRecipeHolder = new RecipeManager(new DynamicRegistryManager$ImmutableImpl(Registries.REGISTRIES.stream().asList())).getFirstMatch(RECIPE_TYPE, RECIPE_TYPE.recipeFor(sourceBlock), world);
- if (sawRecipeHolder.isPresent()) {
- world.breakBlock(sourcePos, false);
- for (ItemStack i : sawRecipeHolder.get().value().getRemainingItems(sourceBlock))
- Block.dropItem(world, sourcePos, stack);
- }
- }
- private static SawBlock.Recipe.Type<SawBlock.Recipe<SawBlock.Recipe.Input>>> getRecipeType () {
- RecipeType<SawBlock.Recipe<SawBlock.Recipe.Input>>> recipe = new RecipeType<SawBlock.Recipe<SawBlock.Recipe.Input>>>() {};
- Registry.register(Registries.RECIPE_TYPE, recipe, Identifier.of("bttc", "saw_milling"));
- return recipe;
- }
- }
- public class MechanicalBlockRecipeRegistry implements MutableRegistry<Entry> {
- private final RegistryKey<Registry<Entry>> key;
- private List<Identifier> keys = List.<Identifier>of();
- private List<Entry> values = List.<Identifier>of();
- private MechanicalBlockRecipeRegistry (ResourceKey<Registry<Entry> key) {
- this.key = key;
- keys.add(Identifier.of("bttc", "default"));
- values.add(Entry.getDefault());
- }
- public ResourceKey<Registry<Entry>> getKey () {
- return this.key;
- }
- public Identifier getId (Entry value) {
- if (values.contains(value))
- return keys.get(values.indexOf(value));
- else
- return null;
- }
- public Optional<RegistryKey<Entry>> getKey (Entry value) {
- if (values.contains(value))
- return Optional.<RegistryKey<Entry>>of(RegistryKey.<Entry>of(this.getKey(), keys.get(values.indexOf(value))));
- else
- return Optional.<RegistryKey<Entry>>empty();
- }
- public int getRawId (Entry value) {
- return values.indexOf(value);
- }
- public Entry get (RegistryKey<Entry> key) {
- if (RegistryKey.getRegistryRef() != this.getKey()) return null;
- return get(key.getValue());
- }
- public Entry get (Identifier id) {
- if (keys.contains(id))
- return values.get(keys.indexOf(id));
- else
- return null;
- }
- public Optional<RegistryEntryInfo> getEntryInfo (RegistryKey<Entry> key) {
- if (get(key) != null)
- return Optional.<RegistryEntryInfo>of(new RegistrationInfo(new VersionedIdentifier(key.getLocation().getNamespace(), SharedConstants.getGameVersion().getId(), key.getLocation().getPath()), Lifecycle.experimental()));
- else
- return Optional.<RegistryEntry>empty();
- }
- public Lifecycle getLifecycle () {
- return Lifecycle.experimental();
- }
- public Optional<RegistryEntry.Reference<Entry>> getDefaultEntry () {
- return Optional.<RegistryEntry.Reference<Entry>>of(RegistryEntry.Reference.<Entry>standAlone(this.getReadOnlyWrapper(), RegistryKey.<Entry>of(this.getKey(), Identifier.of("bttc", "default"))));
- }
- public Set<Identifier> getIds () {
- return Set.<Identifier>copyOf(this.keys);
- }
- public Set<Map.Entry<RegistryKey<Entry>, Entry>> getEntrySet {
- List<AbstractMap.SimpleImmutableEntry<RegistryKey<Entry>, Entry>> entries = List.<AbstractMap.SimpleImmutableEntry<RegistryKey<Entry>, Entry>>of();
- for (Identifier id : this.keys)
- AbstractMap.SimpleImmutableEntry<RegistryKey<Entry>, Entry> = new AbstractMap.SimpleImmutableEntry<RegistryKey<Entry>, Entry>(RegistryKey.<Entry>of(this.getKey(), id), this.get(id));
- return Set.<AbstractMap.SimpleImmutableEntry<RegistryKey<Entry>, Entry>>copyOf(entries);
- }
- public Set<RegistryKey<Entry>> getKeys () {
- Set<RegistryKey<Entry>> getKeys = Set.<RegistryKey<Entry>>of();
- this.getIds().forEach((id) -> { getKeys.add(RegistryKey.<Entry>of(this.getKey(), id)); });
- return getKeys;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement